You are here

public function SimpleMenuBlock::build in Simple Mobile Menu 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Block/SimpleMenuBlock.php \Drupal\simple_mobile_menu\Plugin\Block\SimpleMenuBlock::build()

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/SimpleMenuBlock.php, line 22

Class

SimpleMenuBlock
Provides a Simple Mobile Menu block.

Namespace

Drupal\simple_mobile_menu\Plugin\Block

Code

public function build() {
  $simple_mobile_menu_config = \Drupal::config('simple_mobile_menu.settings')
    ->get('menu_name');
  $block_config = [];
  $block_config['menu_name'][] = $simple_mobile_menu_config;
  $block_config = [
    'menu_name',
    $simple_mobile_menu_config,
  ];

  // Get menu tree.
  $tree = simple_mobile_menu_build_tree($block_config);

  // Build menu class.
  $tree = $this
    ->buildMenuStyle($tree, $block_config);
  $library = [];
  $library[] = 'simple_mobile_menu/simple_mobile_menu';
  return [
    '#theme' => 'simple_mobile_menu',
    '#attached' => [
      'library' => $library,
    ],
    '#menu_output' => \Drupal::service('renderer')
      ->render($tree),
  ];
}