class DefaultSelectionDeriver in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Plugin/Derivative/DefaultSelectionDeriver.php \Drupal\Core\Entity\Plugin\Derivative\DefaultSelectionDeriver
Provides derivative plugins for the DefaultSelection plugin.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\Core\Entity\Plugin\Derivative\DefaultSelectionDeriver implements ContainerDeriverInterface
Expanded class hierarchy of DefaultSelectionDeriver
See also
\Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
\Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager
\Drupal\Core\Entity\Annotation\EntityReferenceSelection
\Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface
File
- core/
lib/ Drupal/ Core/ Entity/ Plugin/ Derivative/ DefaultSelectionDeriver.php, line 24 - Contains \Drupal\Core\Entity\Plugin\Derivative\DefaultSelectionDeriver.
Namespace
Drupal\Core\Entity\Plugin\DerivativeView source
class DefaultSelectionDeriver extends DeriverBase implements ContainerDeriverInterface {
/**
* The entity manager
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Creates an SelectionBase object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $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) {
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id] = $base_plugin_definition;
$this->derivatives[$entity_type_id]['entity_types'] = array(
$entity_type_id,
);
$this->derivatives[$entity_type_id]['label'] = t('@entity_type selection', array(
'@entity_type' => $entity_type
->getLabel(),
));
$this->derivatives[$entity_type_id]['base_plugin_label'] = (string) $base_plugin_definition['label'];
// If the entity type doesn't provide a 'label' key in its plugin
// definition, we have to use the alternate PhpSelection class as default
// plugin, which allows filtering the target entities by their label()
// method. The major downside of PhpSelection is that it is more expensive
// performance-wise than SelectionBase because it has to load all the
// target entities in order to perform the filtering process, regardless
// of whether a limit has been passed.
// @see \Drupal\Core\Entity\Plugin\EntityReferenceSelection\PhpSelection
if (!$entity_type
->hasKey('label')) {
$this->derivatives[$entity_type_id]['class'] = 'Drupal\\Core\\Entity\\Plugin\\EntityReferenceSelection\\PhpSelection';
}
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultSelectionDeriver:: |
protected | property | The entity manager | |
DefaultSelectionDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
DefaultSelectionDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
DefaultSelectionDeriver:: |
public | function | Creates an SelectionBase object. | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |