DefaultSelectionDeriver.php in Drupal 8
File
core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php
View source
<?php
namespace Drupal\Core\Entity\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DefaultSelectionDeriver extends DeriverBase implements ContainerDeriverInterface {
use DeprecatedServicePropertyTrait;
protected $deprecatedProperties = [
'entityManager' => 'entity.manager',
];
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id] = $base_plugin_definition;
$this->derivatives[$entity_type_id]['entity_types'] = [
$entity_type_id,
];
$this->derivatives[$entity_type_id]['label'] = t('@entity_type selection', [
'@entity_type' => $entity_type
->getLabel(),
]);
$this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];
if (!$entity_type
->hasKey('label')) {
$this->derivatives[$entity_type_id]['class'] = 'Drupal\\Core\\Entity\\Plugin\\EntityReferenceSelection\\PhpSelection';
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}