You are here

public function FarmLocalActionsBlock::build in farmOS 2.x

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

See also

\Drupal\block\BlockViewBuilder

File

modules/core/ui/theme/src/Plugin/Block/FarmLocalActionsBlock.php, line 20

Class

FarmLocalActionsBlock
Provides a block to display the local actions.

Namespace

Drupal\farm_ui_theme\Plugin\Block

Code

public function build() {

  // Render local actions as a dropbutton.
  $local_actions = parent::build();
  $links = [];
  foreach ($local_actions as $local_action) {
    if (!empty($local_action['#link']) && $local_action['#access']
      ->isAllowed()) {

      // Copy localized_options into the URL options.
      // This is necessary to maintain any query parameters that were added
      // to the action links.
      $local_action['#link']['url']
        ->setOptions(array_merge($local_action['#link']['url']
        ->getOptions(), $local_action['#link']['localized_options']));

      // Add the link.
      $links[] = $local_action['#link'];
    }
  }
  return [
    '#type' => 'dropbutton',
    '#dropbutton_type' => 'standard',
    '#links' => $links,
    '#cache' => $local_actions['#cache'],
  ];
}