You are here

public function FormModeManagerContextualLinks::getDerivativeDefinitions in Form mode manager 8.2

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/FormModeManagerContextualLinks.php, line 76

Class

FormModeManagerContextualLinks
Provides contextual links definitions for all entity bundles.

Namespace

Drupal\form_mode_manager\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = [];
  foreach ($this->formModesDefinitionsList as $entity_type_id => $form_modes) {

    /** @var \Drupal\form_mode_manager\EntityRoutingMapBase $entity_operation_mapping */
    $entity_operation_mapping = $this->entityRoutingMap
      ->createInstance($entity_type_id, [
      'entityTypeId' => $entity_type_id,
    ]);
    $edit_route_name = $entity_operation_mapping
      ->getOperation("edit_form");
    $this
      ->setDefaultTasks($entity_type_id, $edit_route_name);
    foreach ($form_modes as $form_mode_name => $form_mode) {
      if ($this->formModeManager
        ->hasActiveFormMode($entity_type_id, $form_mode_name)) {
        $form_mode_route_name = "{$edit_route_name}.{$form_mode_name}";
        $this->derivatives[$form_mode_route_name]['route_name'] = $form_mode_route_name;
        $this->derivatives[$form_mode_route_name]['group'] = $entity_type_id;
        $this->derivatives[$form_mode_route_name]['title'] = $this
          ->t('Edit as @form_mode', [
          '@form_mode' => $form_mode['label'],
        ]);
        $this->derivatives[$form_mode_route_name]['cache_tags'] = Cache::mergeTags([
          'form_mode_manager_contextual_links',
        ], $this->cacheTags);
      }
    }
  }
  return $this->derivatives;
}