public function CheeseburgerMenu::build in Cheeseburger Menu 8
Same name and namespace in other branches
- 8.4 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()
Return value
complete block the complete block stored in configuration's 'data' field
Overrides BlockPluginInterface::build
File
- src/
Plugin/ Block/ CheeseburgerMenu.php, line 525
Class
- CheeseburgerMenu
- Plugin annotation @Block( id = "cheesebuger_menu_block", admin_label = @Translation("Cheeseburger Menu"), category = @Translation("Block") )
Namespace
Drupal\cheeseburger_menu\Plugin\BlockCode
public function build() {
$config = $this
->getConfiguration();
$headerHeight = isset($config['headerHeight']) ? $config['headerHeight'] : 0;
$headerPadding = isset($config['headerPadding']) ? $config['headerPadding'] : 0;
$showOnAll = isset($config['breakpoint_all']) ? $config['breakpoint_all'] : TRUE;
$page_type = 'unknown';
if ($route_id = \Drupal::routeMatch()
->getParameters()
->get('taxonomy_term') != NULL) {
$route_id = \Drupal::routeMatch()
->getParameters()
->get('taxonomy_term')
->id();
$page_type = 'taxonomy_term';
}
elseif (\Drupal::routeMatch()
->getParameters()
->get('node') != NULL) {
$route_id = \Drupal::routeMatch()
->getParameters()
->get('node')
->id();
$page_type = 'node';
}
elseif (\Drupal::routeMatch()
->getParameters()
->get('view_id') != NULL) {
$route_id = 'view.' . \Drupal::routeMatch()
->getParameters()
->get('view_id');
$page_type = 'view';
}
elseif (\Drupal::routeMatch()
->getParameters()
->get('user') != NULL) {
$route_id = \Drupal::routeMatch()
->getParameters()
->get('user')
->id();
$page_type = 'user';
}
elseif (\Drupal::routeMatch()
->getRouteName() != NULL) {
$route_id = \Drupal::routeMatch()
->getRouteName();
if (strpos($route_id, 'commerce_cart') !== FALSE) {
$page_type = 'cart';
}
}
else {
$route_id = 0;
$page_type = 'unknown';
}
$current_route = \Drupal\Core\Url::fromRoute('<current>');
$current_route = $current_route
->toString();
if ($showOnAll) {
$controller = new renderCheeseburgerMenuBlock();
$tree = $controller
->render_tree($route_id, $page_type, $current_route, $config);
$tree['#attached']['drupalSettings'] = [
'collapsibleMenu' => 1,
'interactiveParentMenu' => 0,
'headerHeight' => $headerHeight,
'headerPadding' => $headerPadding,
'instant_show' => TRUE,
];
return $tree;
}
else {
$tree = [];
$tree[] = [
'#markup' => '<div class="cheeseburger-menu__menus">',
];
if ($config['css_default']) {
$tree['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.css';
}
$breakpoints = $config['breakpoints'];
foreach ($breakpoints as $key => $breakpoint) {
if ($breakpoint['name'] != NULL && $key != 'All') {
$breakpoints[$key]['mediaQuery'] = str_replace('min', 'max', $breakpoints[$key]['mediaQuery']);
}
}
$tree['#attached'] = [
'drupalSettings' => [
'collapsibleMenu' => 1,
'interactiveParentMenu' => 0,
'headerHeight' => $headerHeight,
'headerPadding' => $headerPadding,
'route_id' => $route_id,
'page_type' => $page_type,
'current_route' => $current_route,
'breakpoints' => $breakpoints,
'block_id' => str_replace('_', '', $config['provider']),
'instant_show' => FALSE,
],
];
$tree[] = [
'#markup' => '</div>',
];
return $tree;
}
}