function PageActions::getFeaturedPageActions

Gets the featured local task.

Parameters

array $page_actions: The array of local tasks for the current page.

Return value

array|null The featured local task definition if available. NULL otherwise.

1 call to PageActions::getFeaturedPageActions()
PageActions::build in core/modules/navigation/src/Plugin/TopBarItem/PageActions.php
Builds and returns the renderable array for this top bar item plugin.

File

core/modules/navigation/src/Plugin/TopBarItem/PageActions.php, line 110

Class

PageActions
Provides the Page Actions basic top bar item.

Namespace

Drupal\navigation\Plugin\TopBarItem

Code

protected function getFeaturedPageActions(array $page_actions) : ?array {
  $featured_page_actions = [];
  $current_route_name = $this->routeMatch
    ->getRouteName();
  $canonical_pattern = '/^entity\\.(.+?)\\.(canonical|latest_version)$/';
  if (preg_match($canonical_pattern, $current_route_name, $matches)) {
    $entity_type = $matches[1];
    $edit_route = "entity.{$entity_type}.edit_form";
    // For core entities, the local task name matches the route name. If
    // needed, we could iterate over the items and check the actual route.
    if (isset($page_actions['page_actions'][$edit_route]) && $page_actions['page_actions'][$edit_route]['#access']?->isAllowed()) {
      $featured_page_actions[$edit_route] = [
        'page_action' => $page_actions['page_actions'][$edit_route],
        'icon' => [
          'icon_id' => 'pencil',
        ],
      ];
    }
  }
  return $featured_page_actions;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.