You are here

public function FormModeManagerLocalAction::setDefaultLocalTask in Form mode manager 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/Derivative/FormModeManagerLocalAction.php \Drupal\form_mode_manager\Plugin\Derivative\FormModeManagerLocalAction::setDefaultLocalTask()

Set default local task.

Parameters

array $form_mode: A form mode.

string $entity_type_id: An entity type id.

string $form_mode_name: A form mode name.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to FormModeManagerLocalAction::setDefaultLocalTask()
FormModeManagerLocalAction::getDerivativeDefinitions in src/Plugin/Derivative/FormModeManagerLocalAction.php
Gets the definition of all derivatives of a base plugin.

File

src/Plugin/Derivative/FormModeManagerLocalAction.php, line 112

Class

FormModeManagerLocalAction
Provides local action definitions for all entity bundles.

Namespace

Drupal\form_mode_manager\Plugin\Derivative

Code

public function setDefaultLocalTask(array $form_mode, $entity_type_id, $form_mode_name) {
  $entity_storage = $this->entityTypeManager
    ->getStorage($entity_type_id);
  $this->derivatives[$form_mode['id']] = [
    'route_name' => "form_mode_manager.{$entity_type_id}.add_page.{$form_mode_name}",
    'title' => $this
      ->t('Add @entity_label as @form_mode', [
      '@form_mode' => $form_mode['label'],
      '@entity_label' => strtolower($entity_storage
        ->getEntityType()
        ->getLabel()),
    ]),
    'route_parameters' => [
      'form_mode_name' => $form_mode_name,
    ],
    // @TODO Use EntityRoutingMap to retrieve generic appears_on.
    'appears_on' => [
      "entity.{$entity_type_id}.collection",
    ],
    'cache_tags' => $this->formModeManager
      ->getListCacheTags(),
  ];

  // In unbundled entity we change route to directly use add_form.
  if (empty($entity_storage
    ->getEntityType()
    ->getKey('bundle'))) {
    $entity_routes_infos = $this->entityRoutingMap
      ->createInstance($entity_type_id, [
      'entityTypeId' => $entity_type_id,
    ])
      ->getPluginDefinition();
    $this->derivatives[$form_mode['id']]['route_name'] = $entity_routes_infos['operations']['add_form'] . ".{$form_mode_name}";
    unset($this->derivatives[$form_mode['id']]['route_parameters']);
  }
}