src/JsonapiExtrasServiceProvider.php | 6 ++--- .../ConfigurableResourceTypeRepository.php | 26 +++++++--------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/JsonapiExtrasServiceProvider.php b/src/JsonapiExtrasServiceProvider.php index 14262d5..f67efe6 100644 --- a/src/JsonapiExtrasServiceProvider.php +++ b/src/JsonapiExtrasServiceProvider.php @@ -23,9 +23,9 @@ class JsonapiExtrasServiceProvider extends ServiceProviderBase { $definition->setClass(ConfigurableResourceTypeRepository::class); // The configurable service expects the entity repository and the enhancer // plugin manager. - $definition->addArgument(new Reference('entity.repository')); - $definition->addArgument(new Reference('plugin.manager.resource_field_enhancer')); - $definition->addArgument(new Reference('config.factory')); + $definition->addMethodCall('setEntityRepository', [new Reference('entity.repository')]); + $definition->addMethodCall('setEnhancerManager', [new Reference('plugin.manager.resource_field_enhancer')]); + $definition->addMethodCall('setConfigFactory', [new Reference('config.factory')]); } $settings = BootstrapConfigStorageFactory::get() diff --git a/src/ResourceType/ConfigurableResourceTypeRepository.php b/src/ResourceType/ConfigurableResourceTypeRepository.php index 9d2201d..f2bbe5e 100644 --- a/src/ResourceType/ConfigurableResourceTypeRepository.php +++ b/src/ResourceType/ConfigurableResourceTypeRepository.php @@ -2,14 +2,11 @@ namespace Drupal\jsonapi_extras\ResourceType; -use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeInterface; -use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\jsonapi\ResourceType\ResourceTypeRepository; use Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerManager; use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Entity\EntityFieldManagerInterface; /** * Provides a repository of JSON API configurable resource types. @@ -36,13 +33,6 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository { protected $enhancerManager; /** - * The bundle manager. - * - * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface - */ - protected $bundleManager; - - /** * The configuration factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface @@ -70,16 +60,16 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository { */ 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); + public function setEntityRepository(EntityRepositoryInterface $entity_repository) { $this->entityRepository = $entity_repository; + } + + public function setEnhancerManager(ResourceFieldEnhancerManager $enhancer_manager) { $this->enhancerManager = $enhancer_manager; + } + + public function setConfigFactory(ConfigFactoryInterface $config_factory) { $this->configFactory = $config_factory; - $this->entityFieldManager = $entity_field_manager; - $this->bundleManager = $bundle_manager; } /** @@ -177,7 +167,7 @@ class ConfigurableResourceTypeRepository extends ResourceTypeRepository { $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)); + $bundles = array_keys($this->entityTypeBundleInfo->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];