/** * @param \FSi\Bundle\ResourceRepositoryBundle\Repository\MapBuilder $mapBuilder * @param \Symfony\Component\Form\FormFactoryInterface $formFactory * @param \FSi\Bundle\AdminBundle\Admin\ResourceRepository\GenericResourceElement $element * @param \FSi\Bundle\ResourceRepositoryBundle\Model\ResourceValueRepository $valueRepository * @param \FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\TextType $resource */ function let($mapBuilder, $formFactory, $element, $valueRepository, $resource) { $mapBuilder->getMap()->willReturn(array('resources' => array('resource_key' => $resource))); $resource->getName()->willReturn('resources.resource_key'); $element->getRepository()->willReturn($valueRepository); $element->getResourceFormOptions()->willReturn(array('form_options')); $this->beConstructedWith($formFactory, $mapBuilder); }
function it_add_form_builder_specified_by_resource_definition(MapBuilder $map, FormBuilder $builder, TextType $resource, FormFactory $factory, FormBuilder $textBuilder) { $map->hasResource('resources.resource_text')->willReturn(true); $map->getResource('resources.resource_text')->shouldBeCalled()->willReturn($resource); $builder->getFormFactory()->willReturn($factory); $resource->getFormBuilder($factory)->shouldBeCalled()->willReturn($textBuilder); $builder->add($textBuilder)->shouldBeCalled(); $this->buildForm($builder, array('resource_key' => 'resources.resource_text')); }
/** * @param \FSi\Bundle\AdminBundle\Admin\Context\Request\HandlerInterface $handler * @param \FSi\Bundle\AdminBundle\Doctrine\Admin\ResourceElement $element * @param \FSi\Bundle\ResourceRepositoryBundle\Repository\MapBuilder $builder * @param \FSi\Bundle\AdminBundle\Admin\ResourceRepository\ResourceFormBuilder $resourceFormBuilder * @param \Symfony\Component\Form\Form $form */ function let($handler, $element, $builder, $resourceFormBuilder, $form) { $builder->getMap()->willReturn(array('resources' => array())); $element->getResourceFormOptions()->willReturn(array()); $element->getKey()->willReturn('resources'); $resourceFormBuilder->build($element)->willReturn($form); $this->beConstructedWith(array($handler), $resourceFormBuilder); $this->setElement($element); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if (!$this->mapBuilder->hasResource($options['resource_key'])) { throw new ResourceFormTypeException(sprintf('"%s" is not a valid resource key', $options['resource_key'])); } $resource = $this->mapBuilder->getResource($options['resource_key']); $resourceFormBuilder = $resource->getFormBuilder($builder->getFormFactory()); $builder->add($resourceFormBuilder); }
function it_removes_entity_when_setting_empty_value(MapBuilder $builder, ResourceRepository $repository, TextType $resource, ResourceEntity $entity) { $resource->getName()->willReturn('resources_group.resource_a.en'); $repository->get('resources_group.resource_a.en')->willReturn($entity); $builder->getResource(Argument::type('string'))->willReturn($resource); $resource->getResourceProperty()->willReturn('textValue'); $repository->remove($entity)->shouldBeCalled(); $this->set('resources_group.resource_a', null); }
/** * @param string $key * @return array * @throws RuntimeException */ private function getResourceGroup($key) { $map = $this->mapBuilder->getMap(); $propertyPath = $this->createPropertyPath($key); $accessor = PropertyAccess::createPropertyAccessor(); $resources = $accessor->getValue($map, $propertyPath); if (!is_array($resources)) { throw new RuntimeException(sprintf('%s its not a resource group key', $key)); } return $resources; }
/** * {@inheritdoc} */ protected function createResource($configuration, $path) { $locale = $this->getCurrentLocale(); if ($this->isTranslatable($configuration)) { $path = sprintf("%s.%s", $path, $locale); } return parent::createResource($configuration, $path); }
/** * @param string $key * @param mixed */ public function set($key, $value) { $resource = $this->builder->getResource($key); $entity = $this->resourceValueRepository->get($resource->getName()); $accessor = PropertyAccess::createPropertyAccessor(); if (isset($entity) && !isset($value)) { $this->resourceValueRepository->remove($entity); return; } if (isset($entity)) { $accessor->setValue($entity, $resource->getResourceProperty(), $value); $this->resourceValueRepository->save($entity); } else { $entity = new $this->resourceValueClass(); $accessor->setValue($entity, $resource->getResourceProperty(), $value); $this->resourceValueRepository->add($entity); } }