getParameter('chill_person.accompanying_period') !== 'hidden') { return; } $definitions = [ 'chill.person.timeline.accompanying_period_opening', 'chill.person.timeline.accompanying_period_closing', ]; foreach ($definitions as $definition) { $container ->removeDefinition($definition); } $definition = $container->getDefinition('chill.main.timeline_builder'); // we have to remove all methods call, and re-add them if not linked // to this service $calls = $definition->getMethodCalls(); foreach ($calls as [$method, $arguments]) { if ('addProvider' !== $method) { continue; } $definition->removeMethodCall('addProvider'); if (false === in_array($arguments[1], $definitions)) { $definition->addMethodCall($method, $arguments); } } } }