Loading src/Entity/JsonapiResourceConfig.php +4 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\jsonapi_extras\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\jsonapi\Routing\Routes; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** Loading Loading @@ -108,8 +110,8 @@ class JsonapiResourceConfig extends ConfigEntityBase { */ protected static function rebuildRoutes() { try { \Drupal::service('jsonapi.resource_type.repository')->reset(); \Drupal::service('router.builder')->setRebuildNeeded(); ConfigurableResourceTypeRepository::reset(); Routes::rebuild(); } catch (ServiceNotFoundException $exception) { // This is intentionally empty. Loading src/Form/JsonapiResourceConfigForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityTypeRepositoryInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\jsonapi\ResourceType\ResourceType; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig; use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -88,7 +88,7 @@ class JsonapiResourceConfigForm extends EntityForm { * * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info * Bundle information service. * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * The JSON:API resource type repository. * @param \Drupal\Core\Entity\EntityFieldManager $field_manager * The entity field manager. Loading @@ -103,7 +103,7 @@ class JsonapiResourceConfigForm extends EntityForm { * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager * The typed config manager. */ public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepository $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request, TypedConfigManagerInterface $typed_config_manager) { public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepositoryInterface $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request, TypedConfigManagerInterface $typed_config_manager) { $this->bundleInfo = $bundle_info; $this->resourceTypeRepository = $resource_type_repository; $this->fieldManager = $field_manager; Loading src/JsonapiResourceConfigListBuilder.php +21 −12 Original line number Diff line number Diff line Loading @@ -8,7 +8,9 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Url; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType; use Drupal\jsonapi_extras\ResourceType\NullJsonapiResourceConfig; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -45,14 +47,14 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { * The entity type. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The storage. * @param \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository $resource_type_repository * The JSON:API configurable resource type repository. * @param ResourceTypeRepositoryInterface $resource_type_repository * The JSON:API resource type repository. * @param \Drupal\Core\Config\ImmutableConfig $config * The config instance. * @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entityTypeManager * Entity type manager. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigurableResourceTypeRepository $resource_type_repository, ImmutableConfig $config, EntityTypeManagerInterface $entityTypeManager = NULL) { public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ResourceTypeRepositoryInterface $resource_type_repository, ImmutableConfig $config, EntityTypeManagerInterface $entityTypeManager = NULL) { parent::__construct($entity_type, $storage); $this->resourceTypeRepository = $resource_type_repository; $this->config = $config; Loading Loading @@ -155,15 +157,17 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { $resource_types = $this->resourceTypeRepository->all(); $default_disabled = $this->config->get('default_disabled'); foreach ($resource_types as $resource_type) { /** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $resource_config */ $resource_config = $resource_type->getJsonapiResourceConfig(); // Other modules may create resource types, e.g. jsonapi_cross_bundles. $resource_config = $resource_type instanceof ConfigurableResourceType ? $resource_type->getJsonapiResourceConfig() : NULL; /** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */ $entity_type_id = $resource_type->getEntityTypeId(); $bundle = $resource_type->getBundle(); $default_group = 'enabled'; if ($resource_type->isInternal() && !$resource_config->get('disabled')) { if ($resource_config && $resource_type->isInternal() && !$resource_config->get('disabled')) { // Either this item is marked internal by the entity-type OR the default // disabled setting is active. if (!$default_disabled) { Loading @@ -181,14 +185,19 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { } $default_group = 'disabled'; } else if (!$resource_config && $resource_type->isInternal()) { continue; } $group = $resource_config->get('disabled') ? 'disabled' : $default_group; $group = ($resource_config && $resource_config->get('disabled')) || (!$resource_config && !$resource_type->isLocatable()) ? 'disabled' : $default_group; $row = [ 'name' => ['#plain_text' => $resource_type->getTypeName()], 'path' => [ '#type' => 'html_tag', '#tag' => 'code', '#value' => sprintf('/%s%s', $prefix, $resource_type->getPath()), '#value' => sprintf('/%s/%s', $prefix, ltrim($resource_type->getPath(), '/')), ], 'state' => [ '#type' => 'html_tag', Loading @@ -200,7 +209,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { ], ], ], 'operations' => [ 'operations' => $resource_config ? [ '#type' => 'operations', '#links' => [ 'overwrite' => [ Loading @@ -212,10 +221,10 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { ]), ], ], ], ]: [], ]; if (!$resource_config instanceof NullJsonapiResourceConfig) { if ($resource_config && !($resource_config instanceof NullJsonapiResourceConfig)) { $row['state']['#value'] = $this->t('Overwritten'); $row['state']['#attributes']['class'][] = 'label--overwritten'; $row['operations']['#links'] = $this->getDefaultOperations($resource_config); Loading src/Normalizer/SchemaFieldDefinitionNormalizer.php +3 −3 Original line number Diff line number Diff line Loading @@ -4,9 +4,9 @@ namespace Drupal\jsonapi_extras\Normalizer; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType; use Drupal\schemata_json_schema\Normalizer\jsonapi\FieldDefinitionNormalizer as SchemataJsonSchemaFieldDefinitionNormalizer; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; /** * Applies field enhancer schema changes to field schema. Loading @@ -23,10 +23,10 @@ class SchemaFieldDefinitionNormalizer extends SchemataJsonSchemaFieldDefinitionN /** * Constructs a SchemaFieldDefinitionNormalizer object. * * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * A resource type repository. */ public function __construct(ResourceTypeRepository $resource_type_repository) { public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) { $this->resourceTypeRepository = $resource_type_repository; } Loading src/Normalizer/SchemataSchemaNormalizer.php +3 −3 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ namespace Drupal\jsonapi_extras\Normalizer; use Drupal\Component\Utility\NestedArray; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\schemata_json_schema\Normalizer\jsonapi\SchemataSchemaNormalizer as SchemataJsonSchemaSchemataSchemaNormalizer; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; /** * Applies JSONAPI Extras attribute overrides to entity schemas. Loading @@ -21,10 +21,10 @@ class SchemataSchemaNormalizer extends SchemataJsonSchemaSchemataSchemaNormalize /** * Constructs a SchemataSchemaNormalizer object. * * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * A resource repository. */ public function __construct(ResourceTypeRepository $resource_type_repository) { public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) { $this->resourceTypeRepository = $resource_type_repository; } Loading Loading
src/Entity/JsonapiResourceConfig.php +4 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,8 @@ namespace Drupal\jsonapi_extras\Entity; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\jsonapi\Routing\Routes; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository; use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** Loading Loading @@ -108,8 +110,8 @@ class JsonapiResourceConfig extends ConfigEntityBase { */ protected static function rebuildRoutes() { try { \Drupal::service('jsonapi.resource_type.repository')->reset(); \Drupal::service('router.builder')->setRebuildNeeded(); ConfigurableResourceTypeRepository::reset(); Routes::rebuild(); } catch (ServiceNotFoundException $exception) { // This is intentionally empty. Loading
src/Form/JsonapiResourceConfigForm.php +3 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ use Drupal\Core\Entity\EntityTypeRepositoryInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\jsonapi\ResourceType\ResourceType; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig; use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -88,7 +88,7 @@ class JsonapiResourceConfigForm extends EntityForm { * * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $bundle_info * Bundle information service. * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * The JSON:API resource type repository. * @param \Drupal\Core\Entity\EntityFieldManager $field_manager * The entity field manager. Loading @@ -103,7 +103,7 @@ class JsonapiResourceConfigForm extends EntityForm { * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager * The typed config manager. */ public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepository $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request, TypedConfigManagerInterface $typed_config_manager) { public function __construct(EntityTypeBundleInfoInterface $bundle_info, ResourceTypeRepositoryInterface $resource_type_repository, EntityFieldManager $field_manager, EntityTypeRepositoryInterface $entity_type_repository, ResourceFieldEnhancerManager $enhancer_manager, ImmutableConfig $config, Request $request, TypedConfigManagerInterface $typed_config_manager) { $this->bundleInfo = $bundle_info; $this->resourceTypeRepository = $resource_type_repository; $this->fieldManager = $field_manager; Loading
src/JsonapiResourceConfigListBuilder.php +21 −12 Original line number Diff line number Diff line Loading @@ -8,7 +8,9 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Url; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\Entity\JsonapiResourceConfig; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType; use Drupal\jsonapi_extras\ResourceType\NullJsonapiResourceConfig; use Symfony\Component\DependencyInjection\ContainerInterface; Loading Loading @@ -45,14 +47,14 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { * The entity type. * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The storage. * @param \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository $resource_type_repository * The JSON:API configurable resource type repository. * @param ResourceTypeRepositoryInterface $resource_type_repository * The JSON:API resource type repository. * @param \Drupal\Core\Config\ImmutableConfig $config * The config instance. * @param \Drupal\Core\Entity\EntityTypeManagerInterface|null $entityTypeManager * Entity type manager. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ConfigurableResourceTypeRepository $resource_type_repository, ImmutableConfig $config, EntityTypeManagerInterface $entityTypeManager = NULL) { public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, ResourceTypeRepositoryInterface $resource_type_repository, ImmutableConfig $config, EntityTypeManagerInterface $entityTypeManager = NULL) { parent::__construct($entity_type, $storage); $this->resourceTypeRepository = $resource_type_repository; $this->config = $config; Loading Loading @@ -155,15 +157,17 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { $resource_types = $this->resourceTypeRepository->all(); $default_disabled = $this->config->get('default_disabled'); foreach ($resource_types as $resource_type) { /** @var \Drupal\jsonapi_extras\Entity\JsonapiResourceConfig $resource_config */ $resource_config = $resource_type->getJsonapiResourceConfig(); // Other modules may create resource types, e.g. jsonapi_cross_bundles. $resource_config = $resource_type instanceof ConfigurableResourceType ? $resource_type->getJsonapiResourceConfig() : NULL; /** @var \Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType $resource_type */ $entity_type_id = $resource_type->getEntityTypeId(); $bundle = $resource_type->getBundle(); $default_group = 'enabled'; if ($resource_type->isInternal() && !$resource_config->get('disabled')) { if ($resource_config && $resource_type->isInternal() && !$resource_config->get('disabled')) { // Either this item is marked internal by the entity-type OR the default // disabled setting is active. if (!$default_disabled) { Loading @@ -181,14 +185,19 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { } $default_group = 'disabled'; } else if (!$resource_config && $resource_type->isInternal()) { continue; } $group = $resource_config->get('disabled') ? 'disabled' : $default_group; $group = ($resource_config && $resource_config->get('disabled')) || (!$resource_config && !$resource_type->isLocatable()) ? 'disabled' : $default_group; $row = [ 'name' => ['#plain_text' => $resource_type->getTypeName()], 'path' => [ '#type' => 'html_tag', '#tag' => 'code', '#value' => sprintf('/%s%s', $prefix, $resource_type->getPath()), '#value' => sprintf('/%s/%s', $prefix, ltrim($resource_type->getPath(), '/')), ], 'state' => [ '#type' => 'html_tag', Loading @@ -200,7 +209,7 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { ], ], ], 'operations' => [ 'operations' => $resource_config ? [ '#type' => 'operations', '#links' => [ 'overwrite' => [ Loading @@ -212,10 +221,10 @@ class JsonapiResourceConfigListBuilder extends ConfigEntityListBuilder { ]), ], ], ], ]: [], ]; if (!$resource_config instanceof NullJsonapiResourceConfig) { if ($resource_config && !($resource_config instanceof NullJsonapiResourceConfig)) { $row['state']['#value'] = $this->t('Overwritten'); $row['state']['#attributes']['class'][] = 'label--overwritten'; $row['operations']['#links'] = $this->getDefaultOperations($resource_config); Loading
src/Normalizer/SchemaFieldDefinitionNormalizer.php +3 −3 Original line number Diff line number Diff line Loading @@ -4,9 +4,9 @@ namespace Drupal\jsonapi_extras\Normalizer; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\jsonapi_extras\ResourceType\ConfigurableResourceType; use Drupal\schemata_json_schema\Normalizer\jsonapi\FieldDefinitionNormalizer as SchemataJsonSchemaFieldDefinitionNormalizer; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; /** * Applies field enhancer schema changes to field schema. Loading @@ -23,10 +23,10 @@ class SchemaFieldDefinitionNormalizer extends SchemataJsonSchemaFieldDefinitionN /** * Constructs a SchemaFieldDefinitionNormalizer object. * * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * A resource type repository. */ public function __construct(ResourceTypeRepository $resource_type_repository) { public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) { $this->resourceTypeRepository = $resource_type_repository; } Loading
src/Normalizer/SchemataSchemaNormalizer.php +3 −3 Original line number Diff line number Diff line Loading @@ -3,8 +3,8 @@ namespace Drupal\jsonapi_extras\Normalizer; use Drupal\Component\Utility\NestedArray; use Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface; use Drupal\schemata_json_schema\Normalizer\jsonapi\SchemataSchemaNormalizer as SchemataJsonSchemaSchemataSchemaNormalizer; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; /** * Applies JSONAPI Extras attribute overrides to entity schemas. Loading @@ -21,10 +21,10 @@ class SchemataSchemaNormalizer extends SchemataJsonSchemaSchemataSchemaNormalize /** * Constructs a SchemataSchemaNormalizer object. * * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepository $resource_type_repository * @param \Drupal\jsonapi\ResourceType\ResourceTypeRepositoryInterface $resource_type_repository * A resource repository. */ public function __construct(ResourceTypeRepository $resource_type_repository) { public function __construct(ResourceTypeRepositoryInterface $resource_type_repository) { $this->resourceTypeRepository = $resource_type_repository; } Loading