Created
July 16, 2026 02:01
-
-
Save RyoK513/7933c70296dbb72b64746e91627f0da6 to your computer and use it in GitHub Desktop.
ダッシュボードのbaserCMSニュースパネルを非表示にするイベント
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace BcThemeSample\Event; | |
| use BaserCore\Event\BcControllerEventListener; | |
| use Cake\Event\Event; | |
| /** | |
| * Class BcThemeSampleControllerEventListener | |
| * | |
| */ | |
| class BcThemeSampleControllerEventListener extends BcControllerEventListener | |
| { | |
| /** | |
| * イベント | |
| * | |
| * @var string[] | |
| */ | |
| public $events = [ | |
| 'BaserCore.Dashboard.beforeRender', | |
| ]; | |
| /** | |
| * 非表示にするダッシュボードパネル(テンプレート名) | |
| * | |
| * @var string[] | |
| */ | |
| protected $hiddenPanels = ['baser_news']; | |
| /** | |
| * ダッシュボード beforeRender | |
| * | |
| * @param Event $event | |
| * @return void | |
| */ | |
| public function baserCoreDashboardBeforeRender(Event $event) | |
| { | |
| $controller = $event->getSubject(); | |
| // 管理画面のダッシュボードのみを対象にする | |
| if ($controller->getRequest()->getParam('prefix') !== 'Admin') { | |
| return; | |
| } | |
| $panels = $controller->viewBuilder()->getVar('panels'); | |
| if (!is_array($panels)) { | |
| return; | |
| } | |
| foreach ($panels as $plugin => $templates) { | |
| foreach ($this->hiddenPanels as $hidden) { | |
| unset($panels[$plugin][$hidden]); | |
| } | |
| } | |
| $controller->set('panels', $panels); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| namespace BcThemeSample; | |
| use BaserCore\BcPlugin; | |
| use BaserCore\Utility\BcEvent; | |
| use Cake\Core\PluginApplicationInterface; | |
| /** | |
| * plugin for BcThemeSample | |
| */ | |
| class BcThemeSamplePlugin extends BcPlugin | |
| { | |
| /** | |
| * bootstrap | |
| * | |
| * @param PluginApplicationInterface $app | |
| * @return void | |
| */ | |
| public function bootstrap(PluginApplicationInterface $app): void | |
| { | |
| parent::bootstrap($app); | |
| BcEvent::registerPluginEvent($this->getName()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment