Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RyoK513/7933c70296dbb72b64746e91627f0da6 to your computer and use it in GitHub Desktop.

Select an option

Save RyoK513/7933c70296dbb72b64746e91627f0da6 to your computer and use it in GitHub Desktop.
ダッシュボードのbaserCMSニュースパネルを非表示にするイベント
<?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);
}
}
<?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