/**
  * @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);
     }
 }
 /**
  * @param \Symfony\Component\Form\FormFactoryInterface $formFactory
  * @param \Symfony\Component\Form\Test\FormBuilderInterface $formBuilder
  * @param \FSi\Bundle\AdminBundle\Admin\ResourceRepository\GenericResourceElement $element
  * @param \FSi\Bundle\ResourceRepositoryBundle\Model\ResourceValueRepository $valueRepository
  * @param \FSi\Bundle\ResourceRepositoryBundle\Model\ResourceValue $resourceValue
  * @param \Symfony\Component\Form\FormInterface $form
  */
 function it_builds_form_for_resource_group($formFactory, $formBuilder, $element, $valueRepository, $resourceValue, $form)
 {
     $element->getKey()->willReturn('resources');
     $valueRepository->get('resources.resource_key')->willReturn($resourceValue);
     $formFactory->createBuilder('form', array('resources_resource_key' => $resourceValue), array('form_options'))->willReturn($formBuilder);
     $formBuilder->add('resources_resource_key', 'resource', array('resource_key' => 'resources.resource_key'))->shouldBeCalled();
     $formBuilder->getForm()->willReturn($form);
     $this->build($element)->shouldReturn($form);
 }
Esempio n. 3
0
 /**
  * @param GenericResourceElement $element
  * @param \FSi\Bundle\ResourceRepositoryBundle\Model\ResourceValueRepository $valueRepository
  * @param array|\FSi\Bundle\ResourceRepositoryBundle\Repository\Resource\Type\ResourceInterface[] $resources
  * @return array
  */
 private function createFormData(GenericResourceElement $element, ResourceValueRepository $valueRepository, array $resources)
 {
     $data = array();
     foreach ($resources as $resourceKey => $resource) {
         $resourceName = $this->buildResourceName($element, $resourceKey);
         $data[$this->normalizeKey($resourceName)] = $valueRepository->get($resource->getName());
     }
     return $data;
 }