Skip to content

Instantly share code, notes, and snippets.

@e0ipso
Created March 31, 2016 10:46
Show Gist options
  • Save e0ipso/d6e4052432abf503e60d629536eb51af to your computer and use it in GitHub Desktop.
Save e0ipso/d6e4052432abf503e60d629536eb51af 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