Skip to content
Snippets Groups Projects
Commit f2babd5d authored by Björn Brala's avatar Björn Brala
Browse files

Issue #3384599: Cleanup Drupal 8 code paths

parent 72b777b7
No related branches found
No related tags found
1 merge request!37Issue #3384599: Cleanup Drupal 8 code paths
Pipeline #17450 passed with warnings
......@@ -82,14 +82,10 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
public function __construct(...$arguments) {
parent::__construct(...$arguments);
// This is needed, as the property is added in Drupal 8.8 and it is not
// yet present in 8.7 or the contrib version of JSON:API at the time.
if (property_exists($this, 'cacheTags')) {
$this->cacheTags = array_merge($this->cacheTags, [
'config:jsonapi_extras.settings',
'config:jsonapi_resource_config_list',
]);
}
$this->cacheTags = array_merge($this->cacheTags, [
'config:jsonapi_extras.settings',
'config:jsonapi_resource_config_list',
]);
}
/**
......@@ -253,84 +249,4 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository {
return NULL;
}
/**
* {@inheritdoc}
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected function getRelatableResourceTypesFromFieldDefinition(FieldDefinitionInterface $field_definition, array $resource_types) {
$item_definition = $field_definition->getItemDefinition();
$entity_type_id = $item_definition->getSetting('target_type');
$handler_settings = $item_definition->getSetting('handler_settings');
$target_bundles = empty($handler_settings['target_bundles']) ? $this->getAllBundlesForEntityType(
$entity_type_id
) : $handler_settings['target_bundles'];
$relatable_resource_types = [];
foreach ($target_bundles as $target_bundle) {
if ($resource_type = static::lookupResourceType(
$resource_types,
$entity_type_id,
$target_bundle
)) {
$relatable_resource_types[] = $resource_type;
}
else {
trigger_error(
sprintf(
'The "%s" at "%s:%s" references the "%s:%s" entity type that does not exist. Please take action.',
$field_definition->getName(),
$field_definition->getTargetEntityTypeId(),
$field_definition->getTargetBundle(),
$entity_type_id,
$target_bundle
),
E_USER_WARNING
);
}
}
return $relatable_resource_types;
}
/**
* {@inheritdoc}
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected function getAllBundlesForEntityType($entity_type_id) {
// Ensure all keys are strings, because numeric values are allowed
// as bundle names and "array_keys()" will cast "42" to 42.
return array_map('strval', array_keys($this->entityTypeBundleInfo->getBundleInfo($entity_type_id)));
}
/**
* Lookups resource type by the internal and public identifiers.
*
* @param \Drupal\jsonapi\ResourceType\ResourceType[] $resource_types
* The list of resource types to do a lookup.
* @param string $entity_type_id
* The entity type of a seekable resource.
* @param string $bundle
* The entity bundle of a seekable resource.
*
* @return \Drupal\jsonapi\ResourceType\ResourceType|null
* The resource type or NULL if it cannot be found.
*
* @todo Remove this code when Drupal 8 support is dropped
*/
protected static function lookupResourceType(array $resource_types, $entity_type_id, $bundle) {
if (isset($resource_types["$entity_type_id--$bundle"])) {
return $resource_types["$entity_type_id--$bundle"];
}
foreach ($resource_types as $resource_type) {
if ($resource_type->getEntityTypeId() === $entity_type_id && $resource_type->getBundle() === $bundle) {
return $resource_type;
}
}
return NULL;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment