You are here

public function UltimenuBlock::build in Ultimenu 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Block/UltimenuBlock.php \Drupal\ultimenu\Plugin\Block\UltimenuBlock::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/UltimenuBlock.php, line 234

Class

UltimenuBlock
Provides an 'Ultimenu' block.

Namespace

Drupal\ultimenu\Plugin\Block

Code

public function build() {
  $menu_name = $this
    ->delta();
  $skin = $this->configuration['skin'];
  $provider = '';
  $skin_name = '';
  $skin_basename = '';

  // Load the specified block skin.
  if (!empty($skin)) {
    $skin_css_path = $this->ultimenuSkin
      ->getPath($skin);
    $skin_basename = $this->ultimenuSkin
      ->getName($skin_css_path);

    // Fetch the skin file name from the setting.
    list($provider, $skin_name) = array_pad(array_map('trim', explode("|", $skin, 2)), 2, NULL);
  }

  // Provide the settings for further process.
  $build['config'] = [
    'bid' => $this
      ->getDerivativeId(),
    'menu_name' => $menu_name,
    'regions' => empty($this->configuration['regions']) ? [] : array_filter($this->configuration['regions']),
    'skin_name' => $skin_name,
    'skin_provider' => $provider,
    'skin_basename' => $skin_basename,
  ] + $this->configuration;
  return $this->ultimenuManager
    ->build($build);
}