function DevelLocalTask::getDerivativeDefinitions

Same name in other branches
  1. 4.x src/Plugin/Derivative/DevelLocalTask.php \Drupal\devel\Plugin\Derivative\DevelLocalTask::getDerivativeDefinitions()

Overrides DeriverBase::getDerivativeDefinitions

File

src/Plugin/Derivative/DevelLocalTask.php, line 42

Class

DevelLocalTask
Provides local task definitions for all entity bundles.

Namespace

Drupal\devel\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    foreach ($this->entityTypeManager
        ->getDefinitions() as $entity_type_id => $entity_type) {
        $has_edit_path = $entity_type->hasLinkTemplate('edit-form');
        $has_canonical_path = $entity_type->hasLinkTemplate('devel-render');
        if ($has_edit_path || $has_canonical_path) {
            $this->derivatives[$entity_type_id . '.devel_tab'] = [
                'route_name' => sprintf('entity.%s.', $entity_type_id) . ($has_edit_path ? 'devel_load' : 'devel_render'),
                'title' => $this->t('Devel'),
                'base_route' => sprintf('entity.%s.', $entity_type_id) . ($has_canonical_path ? "canonical" : "edit_form"),
                'weight' => 100,
            ];
            $this->derivatives[$entity_type_id . '.devel_definition_tab'] = [
                'route_name' => sprintf('entity.%s.devel_definition', $entity_type_id),
                'title' => $this->t('Definition'),
                'parent_id' => sprintf('devel.entities:%s.devel_tab', $entity_type_id),
                'weight' => 100,
            ];
            $this->derivatives[$entity_type_id . 'devel_path_alias_tab'] = [
                'route_name' => sprintf('entity.%s.devel_path_alias', $entity_type_id),
                'title' => $this->t('Path alias'),
                'parent_id' => sprintf('devel.entities:%s.devel_tab', $entity_type_id),
                'weight' => 100,
            ];
            if ($has_canonical_path) {
                $this->derivatives[$entity_type_id . '.devel_render_tab'] = [
                    'route_name' => sprintf('entity.%s.devel_render', $entity_type_id),
                    'weight' => 100,
                    'title' => $this->t('Render'),
                    'parent_id' => sprintf('devel.entities:%s.devel_tab', $entity_type_id),
                ];
            }
            if ($has_edit_path) {
                $this->derivatives[$entity_type_id . '.devel_load_tab'] = [
                    'route_name' => sprintf('entity.%s.devel_load', $entity_type_id),
                    'weight' => 100,
                    'title' => $this->t('Load'),
                    'parent_id' => sprintf('devel.entities:%s.devel_tab', $entity_type_id),
                ];
                $this->derivatives[$entity_type_id . '.devel_load_with_references_tab'] = [
                    'route_name' => sprintf('entity.%s.devel_load_with_references', $entity_type_id),
                    'weight' => 100,
                    'title' => $this->t('Load (with references)'),
                    'parent_id' => sprintf('devel.entities:%s.devel_tab', $entity_type_id),
                ];
            }
        }
    }
    foreach ($this->derivatives as &$entry) {
        $entry += $base_plugin_definition;
    }
    return $this->derivatives;
}