AutoEntityLabelConfigTask.php in Automatic Entity Label 8.2
File
src/Plugin/Derivative/AutoEntityLabelConfigTask.php
View source
<?php
namespace Drupal\auto_entitylabel\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AutoEntityLabelConfigTask extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
protected $entityManager;
public function __construct(EntityTypeManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity.manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
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;
}
}