You are here

function homebox_local_tasks_alter in Homebox 8

Implements hook_local_tasks_alter().

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

./homebox.module, line 63
Homebox module hooks.

Code

function homebox_local_tasks_alter(&$local_tasks) {

  // Add route to display on the user profile page.
  $homebox_storage = \Drupal::entityTypeManager()
    ->getStorage('homebox');
  $homeboxes = $homebox_storage
    ->loadMultiple();

  /* @var \Drupal\homebox\Entity\HomeboxInterface $homebox */
  foreach ($homeboxes as $homebox) {
    if ($homebox
      ->getOptions()['menu']) {
      $local_tasks['homebox.user_profile.layout.' . $homebox
        ->id()] = [
        'id' => 'homebox.user_profile.layout.' . $homebox
          ->id(),
        'title' => $homebox
          ->label(),
        'route_name' => 'homebox.page',
        'base_route' => 'entity.user.canonical',
        'weight' => -100,
        'route_parameters' => [
          'homebox' => $homebox
            ->id(),
        ],
        'class' => '\\Drupal\\Core\\Menu\\LocalTaskDefault',
        'provider' => 'homebox',
        'options' => [],
      ];
    }
  }
}