You are here

public function CheeseburgerMenu::build in Cheeseburger Menu 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()
  2. 8 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()
  3. 8.2 src/Plugin/Block/CheeseburgerMenu.php \Drupal\cheeseburger_menu\Plugin\Block\CheeseburgerMenu::build()

Building block.

Overrides BlockPluginInterface::build

File

src/Plugin/Block/CheeseburgerMenu.php, line 673
Cheeseburger class extends BlockBase.

Class

CheeseburgerMenu
Block info.

Namespace

Drupal\cheeseburger_menu\Plugin\Block

Code

public function build() {
  $config = $this
    ->getConfiguration();
  $headerHeight = isset($config['headerHeight']) ? $config['headerHeight'] : 0;
  $showOnAll = isset($config['breakpoint_all']) ? $config['breakpoint_all'] : TRUE;
  $page_type = 'unknown';
  $parameters = $this->routeMatch
    ->getParameters();

  /**
   * @var $route_id string
   * @var $page_type string
   */
  extract($this
    ->returnParams($parameters));
  $current_route = Url::fromRoute('<current>');
  $current_route = $current_route
    ->toString();
  if ($showOnAll) {
    $controller = new RenderCheeseburgerMenuBlock($this->renderer, $this->menuTree, $this->themeHandler, $this->breakPointManager);
    $tree = $controller
      ->renderTree($route_id, $page_type, $current_route, $config);
    array_unshift($tree, [
      '#markup' => '<div class="cheeseburger-menu__trigger"></div><div class="cheeseburger-menu__wrapper">',
    ]);
    $tree[] = [
      '#markup' => '</div>',
    ];
    $tree['#attached']['drupalSettings'] = [
      'collapsibleMenu' => 1,
      'interactiveParentMenu' => 0,
      'headerHeight' => $headerHeight,
      'instant_show' => TRUE,
    ];
    if ($config['css_default']) {
      $tree['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.css';
    }
    return $tree;
  }
  else {
    $tree = [];
    $tree[] = [
      '#markup' => '<div class="cheeseburger-menu__trigger"></div>
                <div class="cheeseburger-menu__wrapper">',
    ];
    if ($config['css_default']) {
      $tree['#attached']['library'][] = 'cheeseburger_menu/cheeseburger_menu.css';
    }
    $breakpoints = $config['breakpoints'];
    foreach ($breakpoints as $key => $breakpoint) {
      $breakpoints[$key]['mediaQuery'] = str_replace('min', 'max', $breakpoints[$key]['mediaQuery']);
    }
    $tree['#attached'] = [
      'drupalSettings' => [
        'collapsibleMenu' => 1,
        'interactiveParentMenu' => 0,
        'headerHeight' => $headerHeight,
        '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;
  }
}