You are here

public function FieldToolsLocalTask::getDerivativeDefinitions in Field tools 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/FieldToolsLocalTask.php, line 63

Class

FieldToolsLocalTask
Provides local task definitions for all entity bundles.

Namespace

Drupal\field_tools\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  $this->derivatives = array();
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($entity_type
      ->get('field_ui_base_route')) {

      // 'Tools' tab.
      $this->derivatives["field_tools_field_ui_tools_{$entity_type_id}"] = array(
        'route_name' => "field_tools.field_bulk_clone_{$entity_type_id}",
        'weight' => 4,
        'title' => $this
          ->t('Tools'),
        'base_route' => $entity_type
          ->get('field_ui_base_route'),
      );

      // Secondary tools tabs.
      // 'Clone fields' tab.
      $this->derivatives["field_tools_field_clone_{$entity_type_id}"] = array(
        'route_name' => "field_tools.field_bulk_clone_{$entity_type_id}",
        'weight' => 0,
        'title' => $this
          ->t('Clone fields'),
        'base_route' => $entity_type
          ->get('field_ui_base_route'),
        'parent_id' => "field_tools.field_ui_tools:field_tools_field_ui_tools_{$entity_type_id}",
      );

      // 'Clone displays' tab.
      $this->derivatives["field_tools_displays_clone_{$entity_type_id}"] = array(
        'route_name' => "field_tools.displays_clone_{$entity_type_id}",
        'weight' => 5,
        'title' => $this
          ->t('Clone displays'),
        'base_route' => $entity_type
          ->get('field_ui_base_route'),
        'parent_id' => "field_tools.field_ui_tools:field_tools_field_ui_tools_{$entity_type_id}",
      );

      // 'Copy display settings' tab.
      $this->derivatives["field_tools.displays_settings_copy_{$entity_type_id}"] = array(
        'route_name' => "field_tools.displays_settings_copy_{$entity_type_id}",
        'weight' => 5,
        'title' => $this
          ->t('Copy display settings'),
        'base_route' => $entity_type
          ->get('field_ui_base_route'),
        'parent_id' => "field_tools.field_ui_tools:field_tools_field_ui_tools_{$entity_type_id}",
      );

      // 'Export to base fields' tab.
      $this->derivatives["field_tools.export_to_code_{$entity_type_id}"] = array(
        'route_name' => "field_tools.export_to_code_{$entity_type_id}",
        'weight' => 5,
        'title' => $this
          ->t('Export to base fields code'),
        'base_route' => $entity_type
          ->get('field_ui_base_route'),
        'parent_id' => "field_tools.field_ui_tools:field_tools_field_ui_tools_{$entity_type_id}",
      );

      // Single field clone tab.
      $this->derivatives["field_tools_field_clone_single_{$entity_type_id}"] = array(
        'route_name' => "entity.field_config.{$entity_type_id}_field_tools_clone_form",
        'title' => $this
          ->t('Clone'),
        'base_route' => "entity.field_config.{$entity_type_id}_field_edit_form",
        'weight' => 10,
      );
    }
  }
  foreach ($this->derivatives as &$entry) {
    $entry += $base_plugin_definition;
  }
  return $this->derivatives;
}