You are here

public function JsonapiExtrasServiceProvider::alter in JSON:API Extras 8.2

Same name and namespace in other branches
  1. 8.3 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider::alter()
  2. 8 src/JsonapiExtrasServiceProvider.php \Drupal\jsonapi_extras\JsonapiExtrasServiceProvider::alter()

Modifies existing service definitions.

Parameters

ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.

Overrides ServiceProviderBase::alter

File

src/JsonapiExtrasServiceProvider.php, line 19

Class

JsonapiExtrasServiceProvider
Replace the resource type repository for our own configurable version.

Namespace

Drupal\jsonapi_extras

Code

public function alter(ContainerBuilder $container) {
  if ($container
    ->has('jsonapi.resource_type.repository')) {

    // Override the class used for the configurable service.
    $definition = $container
      ->getDefinition('jsonapi.resource_type.repository');
    $definition
      ->setClass(ConfigurableResourceTypeRepository::class);

    // The configurable service expects the entity repository and the enhancer
    // plugin manager.
    $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()
    ->read('jsonapi_extras.settings');
  if ($settings !== FALSE) {
    $container
      ->setParameter('jsonapi.base_path', '/' . $settings['path_prefix']);
  }
}