You are here

public function UserLocalTask::getDerivativeDefinitions in Profile 8

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/UserLocalTask.php, line 47

Class

UserLocalTask
Provides a user page local task for each profile type.

Namespace

Drupal\profile\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];

  // Starting weight for ordering the local tasks.
  $weight = 10;

  /** @var \Drupal\profile\Entity\ProfileTypeInterface[] $profile_types */
  $profile_types = $this->entityTypeManager
    ->getStorage('profile_type')
    ->loadMultiple();
  foreach ($profile_types as $profile_type_id => $profile_type) {
    if ($profile_type
      ->allowsMultiple()) {
      $route_name = 'profile.user_page.multiple';
    }
    else {
      $route_name = 'profile.user_page.single';
    }
    $this->derivatives[$profile_type_id] = [
      'title' => $profile_type
        ->getDisplayLabel() ?: $profile_type
        ->label(),
      'route_name' => $route_name,
      'base_route' => 'entity.user.canonical',
      'route_parameters' => [
        'profile_type' => $profile_type_id,
      ],
      'weight' => ++$weight,
    ] + $base_plugin_definition;
  }
  return $this->derivatives;
}