public function FlagServiceProvider::alter in Flag 8.4
Modifies existing service definitions.
Parameters
ContainerBuilder $container: The ContainerBuilder whose service definitions can be altered.
Overrides ServiceModifierInterface::alter
File
- src/
FlagServiceProvider.php, line 21
Class
- FlagServiceProvider
- Provides a service modifier to support anonymous flaggings.
Namespace
Drupal\flagCode
public function alter(ContainerBuilder $container) {
// Get the CSRF service ID even if it has been aliased.
for ($id = 'access_check.csrf'; $container
->hasAlias($id); $id = (string) $container
->getAlias($id)) {
}
// Hide the original service definition.
$original_definition = $container
->getDefinition($id)
->setPublic(FALSE);
// Replace it with our definition.
$container
->setDefinition("flag.{$id}", $original_definition);
$new_definition = new Definition('Drupal\\flag\\Access\\CsrfAccessCheck', [
new Reference("flag.{$id}"),
new Reference('current_user'),
]);
$new_definition
->setTags($original_definition
->getTags());
$original_definition
->setTags([]);
$container
->setDefinition($id, $new_definition);
}