diff --git a/Block/BlockServiceManager.php b/Block/BlockServiceManager.php index 3c607704..162e4afe 100644 --- a/Block/BlockServiceManager.php +++ b/Block/BlockServiceManager.php @@ -139,7 +139,7 @@ public function getServices() /** * {@inheritdoc} */ - public function getServicesByContext($context) + public function getServicesByContext($context, $includeContainers = true) { if (!array_key_exists($context, $this->contexts)) { return array(); @@ -147,7 +147,13 @@ public function getServicesByContext($context) $services = array(); + $containers = $this->container->getParameter('sonata.block.container.types'); + foreach ($this->contexts[$context] as $name) { + if (!$includeContainers && in_array($name, $containers)) { + continue; + } + $services[$name] = $this->getService($name); } diff --git a/Block/BlockServiceManagerInterface.php b/Block/BlockServiceManagerInterface.php index c8e6404f..48cae689 100644 --- a/Block/BlockServiceManagerInterface.php +++ b/Block/BlockServiceManagerInterface.php @@ -48,11 +48,12 @@ public function setServices(array $blockServices); public function getServices(); /** - * @param string $name + * @param string $name + * @param boolean $includeContainers * * @return array */ - public function getServicesByContext($name); + public function getServicesByContext($name, $includeContainers = true); /** * @param string $name diff --git a/Form/Type/ServiceListType.php b/Form/Type/ServiceListType.php index 6480eeea..1d7d5334 100644 --- a/Form/Type/ServiceListType.php +++ b/Form/Type/ServiceListType.php @@ -63,26 +63,27 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) 'expanded' => false, 'choices' => function (Options $options, $previousValue) use ($manager) { $types = array(); - foreach ($manager->getServicesByContext($options['context']) as $code => $service) { + foreach ($manager->getServicesByContext($options['context'], $options['include_containers']) as $code => $service) { $types[$code] = sprintf('%s - %s', $service->getName(), $code); } return $types; }, - 'preferred_choices' => array(), - 'empty_data' => function (Options $options) { + 'preferred_choices' => array(), + 'empty_data' => function (Options $options) { $multiple = isset($options['multiple']) && $options['multiple']; $expanded = isset($options['expanded']) && $options['expanded']; return $multiple || $expanded ? array() : ''; }, - 'empty_value' => function (Options $options, $previousValue) { + 'empty_value' => function (Options $options, $previousValue) { $multiple = isset($options['multiple']) && $options['multiple']; $expanded = isset($options['expanded']) && $options['expanded']; return $multiple || $expanded || !isset($previousValue) ? null : ''; }, - 'error_bubbling' => false, + 'error_bubbling' => false, + 'include_containers' => false )); } }