EntityFieldDeriverBase.php in GraphQL 8.3
File
modules/graphql_core/src/Plugin/Deriver/EntityFieldDeriverBase.php
View source
<?php
namespace Drupal\graphql_core\Plugin\Deriver;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class EntityFieldDeriverBase extends DeriverBase implements ContainerDeriverInterface {
use DependencySerializationTrait;
protected abstract function getDerivativeDefinitionsFromFieldDefinition(FieldDefinitionInterface $fieldDefinition, array $basePluginDefinition);
protected $entityTypeManager;
protected $entityFieldManager;
protected $entityBundleInfo;
protected $basePluginId;
public static function create(ContainerInterface $container, $basePluginId) {
return new static($container
->get('entity_type.manager'), $container
->get('entity_field.manager'), $container
->get('entity_type.bundle.info'), $basePluginId);
}
public function __construct(EntityTypeManagerInterface $entityTypeManager, EntityFieldManagerInterface $entityFieldManager, EntityTypeBundleInfoInterface $entityTypeBundleInfo, $basePluginId) {
$this->basePluginId = $basePluginId;
$this->entityTypeManager = $entityTypeManager;
$this->entityFieldManager = $entityFieldManager;
$this->entityBundleInfo = $entityTypeBundleInfo;
}
public function getDerivativeDefinitions($basePluginDefinition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entityTypeId => $entityType) {
if (!$entityType
->entityClassImplements(FieldableEntityInterface::class)) {
continue;
}
foreach ($this->entityFieldManager
->getBaseFieldDefinitions($entityTypeId) as $fieldDefinition) {
if ($derivatives = $this
->getDerivativeDefinitionsFromFieldDefinition($fieldDefinition, $basePluginDefinition)) {
$this->derivatives = array_merge($this->derivatives, $derivatives);
}
}
foreach ($this->entityBundleInfo
->getBundleInfo($entityTypeId) as $bundleId => $bundleInfo) {
foreach ($this->entityFieldManager
->getFieldDefinitions($entityTypeId, $bundleId) as $fieldDefinition) {
if ($derivatives = $this
->getDerivativeDefinitionsFromFieldDefinition($fieldDefinition, $basePluginDefinition)) {
$this->derivatives = array_merge($this->derivatives, $derivatives);
}
}
}
}
return $this->derivatives;
}
}