public function CheeseburgerMenuBlock::build in Cheeseburger Menu 5.0.x
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides BlockPluginInterface::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ CheeseburgerMenuBlock.php, line 408
Class
- CheeseburgerMenuBlock
- Provides a 'CheeseburgerMenu' block.
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function build() {
$menus = [];
foreach ($this
->getConfigValue('menus') as $menu) {
switch ($menu['menu_type']) {
case 'taxonomy_vocabulary':
$menus[$menu['id']] = $this->service
->buildMenuFromVocabulary($menu, $this
->getConfigValue('parent_menu_as_link'));
break;
case 'menu':
$menus[$menu['id']] = $this->service
->buildMenu($menu, $this
->getConfigValue('parent_menu_as_link'));
break;
}
}
if ($this
->getConfigValue('invoke_hooks')) {
$this
->createHooks($menus);
}
$build = [
'#theme' => 'cheeseburger_menu',
'#tree' => $menus,
'#show_navigation' => $this
->getConfigValue('show_navigation'),
];
if ($this
->getConfigValue('default_css')) {
$build['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.css';
}
if ($this
->getConfigValue('default_js')) {
$build['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.js';
}
return $build;
}