class ConfigurableResourceTypeRepository in JSON:API Extras 8
Same name and namespace in other branches
- 8.3 src/ResourceType/ConfigurableResourceTypeRepository.php \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository
- 8.2 src/ResourceType/ConfigurableResourceTypeRepository.php \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository
Provides a repository of JSON API configurable resource types.
Hierarchy
- class \Drupal\jsonapi\ResourceType\ResourceTypeRepository implements ResourceTypeRepositoryInterface
- class \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository
Expanded class hierarchy of ConfigurableResourceTypeRepository
2 files declare their use of ConfigurableResourceTypeRepository
File
- src/
ResourceType/ ConfigurableResourceTypeRepository.php, line 16
Namespace
Drupal\jsonapi_extras\ResourceTypeView source
class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
/**
* The entity repository.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface
*/
protected $entityRepository;
/**
* Plugin manager for enhancers.
*
* @var \Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager
*/
protected $enhancerManager;
/**
* The bundle manager.
*
* @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface
*/
protected $bundleManager;
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* A list of all resource types.
*
* @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType[]
*/
protected $resourceTypes;
/**
* A list of only enabled resource types.
*
* @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType[]
*/
protected $enabledResourceTypes;
/**
* A list of all resource configuration entities.
*
* @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig[]
*/
protected $resourceConfigs;
/**
* {@inheritdoc}
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_manager, EntityFieldManagerInterface $entity_field_manager, EntityRepositoryInterface $entity_repository, ResourceFieldEnhancerManager $enhancer_manager, ConfigFactoryInterface $config_factory) {
parent::__construct($entity_type_manager, $bundle_manager, $entity_field_manager);
$this->entityRepository = $entity_repository;
$this->enhancerManager = $enhancer_manager;
$this->configFactory = $config_factory;
$this->entityFieldManager = $entity_field_manager;
$this->bundleManager = $bundle_manager;
}
/**
* {@inheritdoc}
*/
public function all() {
if (!$this->all) {
foreach ($this
->getEntityTypeBundleTuples() as $tuple) {
list($entity_type_id, $bundle) = $tuple;
$resource_config_id = sprintf('%s--%s', $entity_type_id, $bundle);
$this->all[] = new ConfigurableResourceType($entity_type_id, $bundle, $this->entityTypeManager
->getDefinition($entity_type_id)
->getClass(), $this
->getResourceConfig($resource_config_id), $this->enhancerManager, $this->configFactory);
}
foreach ($this->all as $resource_type) {
$relatable_resource_types = $this
->calculateRelatableResourceTypes($resource_type);
$resource_type
->setRelatableResourceTypes($relatable_resource_types);
}
}
return $this->all;
}
/**
* Get a single resource configuration entity by its ID.
*
* @param string $resource_config_id
* The configuration entity ID.
*
* @return \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
protected function getResourceConfig($resource_config_id) {
$resource_configs = $this
->getResourceConfigs();
return isset($resource_configs[$resource_config_id]) ? $resource_configs[$resource_config_id] : new NullJsonapiResourceConfig([], '');
}
/**
* Load all resource configuration entities.
*
* @return \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig[]
* The resource config entities.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
function getResourceConfigs() {
if (!$this->resourceConfigs) {
$resource_config_ids = [];
foreach ($this
->getEntityTypeBundleTuples() as $tuple) {
list($entity_type_id, $bundle) = $tuple;
$resource_config_ids[] = sprintf('%s--%s', $entity_type_id, $bundle);
}
$this->resourceConfigs = $this->entityTypeManager
->getStorage('jsonapi_resource_config')
->loadMultiple($resource_config_ids);
}
return $this->resourceConfigs;
}
/**
* Entity type ID and bundle iterator.
*
* @return array
* A list of entity type ID and bundle tuples.
*/
protected function getEntityTypeBundleTuples() {
$entity_type_ids = array_keys($this->entityTypeManager
->getDefinitions());
// For each entity type return as many tuples as bundles.
return array_reduce($entity_type_ids, function ($carry, $entity_type_id) {
$bundles = array_keys($this->bundleManager
->getBundleInfo($entity_type_id));
// Get all the tuples for the current entity type.
$tuples = array_map(function ($bundle) use ($entity_type_id) {
return [
$entity_type_id,
$bundle,
];
}, $bundles);
// Append the tuples to the aggregated list.
return array_merge($carry, $tuples);
}, []);
}
/**
* {@inheritdoc}
*/
public function getPathPrefix() {
return $this->configFactory
->get('jsonapi_extras.settings')
->get('path_prefix');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigurableResourceTypeRepository:: |
protected | property | The bundle manager. | |
ConfigurableResourceTypeRepository:: |
protected | property | The configuration factory. | |
ConfigurableResourceTypeRepository:: |
protected | property | A list of only enabled resource types. | |
ConfigurableResourceTypeRepository:: |
protected | property | Plugin manager for enhancers. | |
ConfigurableResourceTypeRepository:: |
protected | property | The entity repository. | |
ConfigurableResourceTypeRepository:: |
protected | property | A list of all resource configuration entities. | |
ConfigurableResourceTypeRepository:: |
protected | property | A list of all resource types. | |
ConfigurableResourceTypeRepository:: |
public | function |
Gets all JSON:API resource types. Overrides ResourceTypeRepository:: |
|
ConfigurableResourceTypeRepository:: |
protected | function | Entity type ID and bundle iterator. | |
ConfigurableResourceTypeRepository:: |
public | function | ||
ConfigurableResourceTypeRepository:: |
protected | function | Get a single resource configuration entity by its ID. | |
ConfigurableResourceTypeRepository:: |
function | Load all resource configuration entities. | ||
ConfigurableResourceTypeRepository:: |
public | function |
Instantiates a ResourceTypeRepository object. Overrides ResourceTypeRepository:: |
|
ResourceTypeRepository:: |
protected | property | The cache backend. | |
ResourceTypeRepository:: |
protected | property | Cache tags used for caching the repository. | |
ResourceTypeRepository:: |
protected | property | The entity field manager. | |
ResourceTypeRepository:: |
protected | property | The bundle manager. | |
ResourceTypeRepository:: |
protected | property | The entity type manager. | |
ResourceTypeRepository:: |
protected | property | The event dispatcher. | |
ResourceTypeRepository:: |
protected | function | Calculates relatable JSON:API resource types for a given resource type. | |
ResourceTypeRepository:: |
protected | function | Creates a ResourceType value object for the given entity type + bundle. | 1 |
ResourceTypeRepository:: |
public | function |
Gets a specific JSON:API resource type based on entity type ID and bundle. Overrides ResourceTypeRepositoryInterface:: |
|
ResourceTypeRepository:: |
protected | function | Gets all bundle IDs for a given entity type. | |
ResourceTypeRepository:: |
protected | function | Gets all field names for a given entity type and bundle. | |
ResourceTypeRepository:: |
public | function |
Gets a specific JSON:API resource type based on a supplied typename. Overrides ResourceTypeRepositoryInterface:: |
|
ResourceTypeRepository:: |
protected | function | Gets the field mapping for the given field names and entity type + bundle. | |
ResourceTypeRepository:: |
protected | function | Gets the field mapping for the given field names and entity type + bundle. | 1 |
ResourceTypeRepository:: |
protected | function | Get relatable resource types from a field definition. | |
ResourceTypeRepository:: |
protected static | function | Whether an entity type + bundle maps to a locatable resource type. | |
ResourceTypeRepository:: |
protected static | function | Whether an entity type + bundle maps to a mutable resource type. | |
ResourceTypeRepository:: |
protected | function | Determines if a given field definition is a reference field. | |
ResourceTypeRepository:: |
protected static | function | Whether an entity type is a versionable resource type. |