You are here

class AutoEntityLabelConfigTask in Automatic Entity Label 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Derivative/AutoEntityLabelConfigTask.php \Drupal\auto_entitylabel\Plugin\Derivative\AutoEntityLabelConfigTask
  2. 8 src/Plugin/Derivative/AutoEntityLabelConfigTask.php \Drupal\auto_entitylabel\Plugin\Derivative\AutoEntityLabelConfigTask

Class for Config Task.

Hierarchy

Expanded class hierarchy of AutoEntityLabelConfigTask

1 string reference to 'AutoEntityLabelConfigTask'
auto_entitylabel.links.task.yml in ./auto_entitylabel.links.task.yml
auto_entitylabel.links.task.yml

File

src/Plugin/Derivative/AutoEntityLabelConfigTask.php, line 14

Namespace

Drupal\auto_entitylabel\Plugin\Derivative
View source
class AutoEntityLabelConfigTask extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityManager;

  /**
   * Creates an FieldUiLocalTask object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_manager) {
    $this->entityManager = $entity_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    foreach ($this->entityManager
      ->getDefinitions() as $entity_type_id => $entity_type) {

      // Special handling of Taxonomy. See https://www.drupal.org/node/2822546
      if ($entity_type_id == "taxonomy_vocabulary") {
        $base_route = "entity.{$entity_type_id}.overview_form";
      }
      else {
        $base_route = "entity.{$entity_type_id}.edit_form";
      }
      if ($entity_type
        ->hasLinkTemplate('auto-label')) {
        $this->derivatives["{$entity_type_id}.auto_label_tab"] = [
          'route_name' => "entity.{$entity_type_id}.auto_label",
          'title' => $this
            ->t('Automatic label'),
          'base_route' => $base_route,
          'weight' => 100,
        ];
      }
    }
    foreach ($this->derivatives as &$entry) {
      $entry += $base_plugin_definition;
    }
    return $this->derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AutoEntityLabelConfigTask::$entityManager protected property The entity manager.
AutoEntityLabelConfigTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
AutoEntityLabelConfigTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
AutoEntityLabelConfigTask::__construct public function Creates an FieldUiLocalTask object.
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
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.