You are here

public function FieldMenuBlock::build in Menu item content fields 8

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 SystemMenuBlock::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/FieldMenuBlock.php, line 89

Class

FieldMenuBlock
Provides a drupal menu that uses display view modes.

Namespace

Drupal\menu_item_fields\Plugin\Block

Code

public function build() {
  $build = parent::build();
  if (isset($build['#theme'])) {
    $build['#theme'] = $this
      ->addThemeSuggestion($build['#theme']);
  }
  $build['#view_mode'] = $this->configuration['view_mode'];
  if ($this->configuration['view_mode_override_field'] != '_none') {
    $build['#view_mode_override_field'] = $this->configuration['view_mode_override_field'];
  }

  // TODO: inject this dependency.
  $moduleHandler = \Drupal::service('module_handler');
  if ($moduleHandler
    ->moduleExists('menu_ui')) {
    $menuName = $this
      ->getDerivativeId();
    $build['#contextual_links']['menu'] = [
      'route_parameters' => [
        'menu' => $menuName,
      ],
    ];
  }
  return $build;
}