EntityDeriver.php in Zircon Profile 8.0
File
core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php
View source
<?php
namespace Drupal\Core\Entity\Plugin\DataType\Deriver;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityDeriver implements ContainerDeriverInterface {
protected $derivatives = array();
protected $basePluginId;
protected $entityManager;
public function __construct($base_plugin_id, EntityManagerInterface $entity_manager) {
$this->basePluginId = $base_plugin_id;
$this->entityManager = $entity_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity.manager'));
}
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
return $this->derivatives[$derivative_id];
}
$this
->getDerivativeDefinitions($base_plugin_definition);
if (isset($this->derivatives[$derivative_id])) {
return $this->derivatives[$derivative_id];
}
}
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives[''] = $base_plugin_definition;
foreach ($this->entityManager
->getDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives[$entity_type_id] = array(
'label' => $entity_type
->getLabel(),
'constraints' => $entity_type
->getConstraints(),
) + $base_plugin_definition;
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
if ($bundle !== $entity_type_id) {
$this->derivatives[$entity_type_id . ':' . $bundle] = array(
'label' => $bundle_info['label'],
'constraints' => $this->derivatives[$entity_type_id]['constraints'],
) + $base_plugin_definition;
}
}
}
return $this->derivatives;
}
}
Classes
Name |
Description |
EntityDeriver |
Provides data type plugins for each existing entity type and bundle. |