You are here

public function NiceMenusBlock::build in Nice Menus 8

Return value

array

Overrides BlockPluginInterface::build

File

src/Plugin/Block/NiceMenusBlock.php, line 172

Class

NiceMenusBlock
Provides a 'Nice menus' block.

Namespace

Drupal\nice_menus\Plugin\Block

Code

public function build() {
  $block_config = $this
    ->getBlockConfigExtended();
  $config = \Drupal::config('nice_menus.settings');

  // attach library.
  $library = [];

  // load nice_menus.css
  $library[] = 'nice_menus/nice_menus_css';
  if ($config
    ->get('nice_menus_js')) {
    $library[] = 'nice_menus/superfish';
    $library[] = 'nice_menus/jquery.hoverIntent';
    $library[] = 'nice_menus/nice_menus';
  }

  // load nice menus default css.
  if ($config
    ->get('nice_menus_default_css')) {
    $library[] = 'nice_menus/nice_menus_default';
  }

  // get menu tree.
  $tree = nice_menus_build_tree($block_config);

  // build menu class.
  $tree = $this
    ->_build_menu_style($tree, $block_config);

  /**
   * @TODO suupoert responsive.
   * @TODO display title.
   */
  return array(
    '#theme' => 'nice_menus',
    '#attached' => array(
      'library' => $library,
      'drupalSettings' => array(
        'nice_menus_options' => array(
          'delay' => $config
            ->get('nice_menus_sf_delay'),
          'speed' => $config
            ->get('nice_menus_sf_speed'),
        ),
      ),
    ),
    '#menu_output' => $tree,
  );
}