Skip to content

Instantly share code, notes, and snippets.

@itsekhmistro
Forked from e0ipso/service-decorator.php
Last active July 13, 2016 07:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsekhmistro/d94c86e9ee42eb221f46539c6371c781 to your computer and use it in GitHub Desktop.
Save itsekhmistro/d94c86e9ee42eb221f46539c6371c781 to your computer and use it in GitHub Desktop.
Swap out service for a decorator
<?php
/**
* @file
* Contains Drupal\my_module\MyModuleServiceProvider
*/
namespace Drupal\my_module;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
/**
* Modifies the language manager service.
*/
class MyModuleServiceProvider extends ServiceProviderBase {
/**
* {@inheritdoc}
*/
public function alter(ContainerBuilder $container) {
// Overrides entity.manager service for our own.
$currentService = $container->get('entity.manager');
$container->set('entity.manager', new MyEntityManagerDecorator($currentService));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment