You are here

class EckEntityContentLocalTask in Entity Construction Kit (ECK) 8

Provides local task definitions for all entity bundles.

Hierarchy

Expanded class hierarchy of EckEntityContentLocalTask

1 string reference to 'EckEntityContentLocalTask'
eck.links.task.yml in ./eck.links.task.yml
eck.links.task.yml

File

src/Plugin/Derivative/EckEntityContentLocalTask.php, line 15

Namespace

Drupal\eck\Plugin\Derivative
View source
class EckEntityContentLocalTask extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;
  private $basePluginDefinition;

  /**
   * The constructor.
   *
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The translation manager.
   */
  public function __construct(TranslationInterface $string_translation) {
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('string_translation'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($basePluginDefinition) {
    $this->basePluginDefinition = $basePluginDefinition;
    $derivatives = [];

    /** @var \Drupal\eck\Entity\EckEntityType $type */
    foreach (EckEntityType::loadMultiple() as $type) {
      $entity_type = $type
        ->id();
      $base_route = "entity.{$entity_type}.canonical";
      $derivative = $this
        ->createDerivativeDefinition("entity.{$entity_type}.canonical", 1, 'View', $base_route);
      $derivatives["{$entity_type}.eck_canonical_tab"] = $derivative;
      $derivative = $this
        ->createDerivativeDefinition("entity.{$entity_type}.edit_form", 2, 'Edit', $base_route);
      $derivatives["{$entity_type}.eck_edit_tab"] = $derivative;
      $derivative = $this
        ->createDerivativeDefinition("entity.{$entity_type}.delete_form", 3, 'Delete', $base_route);
      $derivatives["{$entity_type}.eck_delete_tab"] = $derivative;
    }
    return $derivatives;
  }

  /**
   * Creates a derivative definition.
   *
   * @param string $routeName
   *   The route name.
   * @param int $weight
   *   The weight.
   * @param string $title
   *   The title.
   * @param string $base_route
   *   The base route.
   *
   * @return array
   *   The created derivative definition.
   */
  private function createDerivativeDefinition($routeName, $weight, $title, $base_route) {
    $derivative = [
      'route_name' => $routeName,
      'weight' => $weight,
      'title' => $this
        ->t($title),
      'base_route' => $base_route,
    ] + $this->basePluginDefinition;
    return $derivative;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
EckEntityContentLocalTask::$basePluginDefinition private property
EckEntityContentLocalTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
EckEntityContentLocalTask::createDerivativeDefinition private function Creates a derivative definition.
EckEntityContentLocalTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
EckEntityContentLocalTask::__construct public function The constructor.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.