public function CheeseburgerMenu::build in Cheeseburger Menu 8.4
Same name and namespace in other branches
- 8 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()
- 8.2 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()
- 8.3 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()
Building block.
Overrides BlockPluginInterface::build
File
- src/
Plugin/ Block/ CheeseburgerMenu.php, line 571 - Cheeseburger class extends BlockBase.
Class
- CheeseburgerMenu
- Block info.
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
if (!$this
->validateConfiguration($config)) {
if ($this
->identifyOldConfig($config)) {
$this->messenger
->addWarning($this
->t('Your current Cheeseburger Menu block configuration is not compatible with the newest release. You can either go edit the block and adjust its settings or, even better, delete the block and place it again.'), 'warning');
$this->messenger
->addWarning($this
->t('We are assuming that you have an old version of the Cheeseburger Menu, so take a note that there are some major changes in the new one, like the default CSS with the full design (you can turn it on/off in block settings).'));
}
else {
$this->messenger
->addWarning($this
->t('Your cheeseburger menu block configuration is not valid, try to save it again in block edit.'), 'warning');
}
return [
'#cache' => [
'max-age' => 0,
],
];
}
$url = Url::fromRouteMatch($this->routeMatch)
->toString();
$headerHeight = isset($config['header_height']) ? $config['header_height'] : 0;
$display_style = $config['hidden_by_default'] ? 'display: none; ' : '';
// TODO FIX THIS.
$render[] = [
'#type' => 'inline_template',
'#template' => '<div class="cheeseburger-menu__trigger"></div>
<div class="cheeseburger-menu__wrapper" style="' . $display_style . 'top: ' . $headerHeight . 'px">',
];
$render['#attached']['drupalSettings'] = [
'instant_show' => $config['breakpoints']['all'],
'breakpoints' => $config['breakpoints']['all'] ? [] : $this
->formatBreakpoints($config['breakpoints']),
'current_route' => $url,
'headerHeight' => $headerHeight,
'block_id' => $this
->getBlockMachineName(),
];
if ($config['breakpoints']['all']) {
$render[] = $this->renderCheesebugerMenuService
->renderTree($config, $url);
}
$render[] = [
'#markup' => '</div>',
];
if ($config['css_default']) {
$render['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.css';
}
return $render;
}