WeMegaMenuBlock.php in Drupal Mega Menu 8
File
src/Plugin/Block/WeMegaMenuBlock.php
View source
<?php
namespace Drupal\we_megamenu\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Cache\Cache;
use Drupal\we_megamenu\WeMegaMenuBuilder;
class WeMegaMenuBlock extends BlockBase {
public function build() {
$build = [
'#theme' => 'we_megamenu_frontend',
'#menu_name' => $this
->getDerivativeId(),
'#blocks' => WeMegaMenuBuilder::getAllBlocks(),
'#block_theme' => \Drupal::config('system.theme')
->get('default'),
'#attached' => [
'library' => [
'we_megamenu/form.we-mega-menu-frontend',
],
],
];
return $build;
}
public function defaultConfiguration() {
return [
'label_display' => FALSE,
];
}
public function getCacheTags() {
$menu_name = $this
->getDerivativeId();
$id_menu = 'config:system.menu.' . $menu_name;
$ids = [
$id_menu,
];
return Cache::mergeTags(parent::getCacheTags(), $ids);
}
public function getCacheContexts() {
$menu_name = $this
->getDerivativeId();
$id_menu = 'route.menu_active_trails:' . $menu_name;
$ids = [
$id_menu,
];
return Cache::mergeContexts(parent::getCacheContexts(), $ids);
}
}