You are here

public function CommerceProductServiceProvider::alter in Commerce Core 8.2

Modifies existing service definitions.

Parameters

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

Overrides ServiceProviderBase::alter

File

modules/product/src/CommerceProductServiceProvider.php, line 17

Class

CommerceProductServiceProvider
Swap field rendered when layout builder module is on.

Namespace

Drupal\commerce_product

Code

public function alter(ContainerBuilder $container) {

  // Get list of modules.
  $modules = $container
    ->getParameter('container.modules');

  // Check if there is layout builder and swap field renderer service.
  if (isset($modules['layout_builder'])) {
    $definition = $container
      ->getDefinition('commerce_product.variation_field_renderer');
    $definition
      ->setClass(ProductVariationFieldRendererLayoutBuilder::class)
      ->addArgument(new Reference('entity_display.repository'));
  }
}