/**
  * {@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_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 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);
     }
 }
 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);
 }