예제 #1
0
 /**
  * Create empty values for non-persisted values
  *
  * @param LifeCycleEventArgs $args
  *
  * @return void
  */
 public function postLoad(LifeCycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($entity instanceof ValueSetInterface && $entity->getValues() !== null) {
         $this->eavManager->replaceEmptyValues($entity);
     }
 }
예제 #2
0
 public function testInitializeEntity()
 {
     $eavManager = new EavManager($this->pool, 'Opifer\\EavBundle\\Tests\\TestData\\ValueSet');
     $schema = new Schema();
     $schema->setObjectClass('Opifer\\EavBundle\\Tests\\TestData\\Entity');
     $entity = $eavManager->initializeEntity($schema);
     $this->assertInstanceOf('Opifer\\EavBundle\\Model\\EntityInterface', $entity);
 }
예제 #3
0
 public function testParseLevel2NestedTypeName()
 {
     $key = 'nested_content__blocks__nesting__0__blocks__nesting__3';
     $manager = new EavManager($this->pool, 'Opifer\\EavBundle\\Tests\\TestData\\ValueSet');
     $expected = ['level' => 2, 'index' => 3, 'reference' => 'nesting', 'attribute' => 'blocks', 'key' => 'nested_content__blocks__nesting__0__blocks__nesting__3'];
     $actual = $manager->parseNestedTypeName($key);
     $this->assertEquals($expected, $actual);
 }
예제 #4
0
 /**
  * Get a form by a schema
  *
  * @param string $schema
  *
  * @return FormView
  */
 public function formFromValue(FormValue $value)
 {
     if (null === ($schema = $value->getSchema())) {
         return false;
     }
     $entity = $this->eavManager->initializeEntity($schema);
     $form = $this->formFactory->create('eav_post', $entity, ['valueId' => $value->getId()]);
     return $form->createView();
 }
예제 #5
0
 public function getViewParameters(BlockInterface $block)
 {
     $parameters = ['block_service' => $this, 'block' => $block];
     if (!empty($block->getForm())) {
         /** @var PostInterface $post */
         $post = $this->eavManager->initializeEntity($parameters['block']->getForm()->getSchema());
         $this->prefillPost($post);
         $form = $this->formManager->createForm($block->getForm(), $post);
         $parameters['block']->formView = $form->createView();
     }
     return $parameters;
 }
예제 #6
0
 /**
  * Get the content by a reference
  *
  * If the passed reference is a numeric, it must be the content ID from a
  * to-be-updated content item.
  * If not, the reference must be the template name for a to-be-created
  * content item.
  *
  * @param int|string $reference
  *
  * @return ContentInterface
  */
 public function getContentByReference($reference)
 {
     if (is_numeric($reference)) {
         // If the reference is numeric, it must be the content ID from an existing
         // content item, which has to be updated.
         $nestedContent = $this->getRepository()->find($reference);
     } else {
         // If not, $reference is a template name for a to-be-created content item.
         $template = $this->em->getRepository($this->templateClass)->findOneByName($reference);
         $nestedContent = $this->eavManager->initializeEntity($template);
         $nestedContent->setNestedDefaults();
     }
     return $nestedContent;
 }
예제 #7
0
 /**
  * Builds a Symfony form from the passed Form entity and returns the related FormView,
  * so we can use our Form as a standard Symfony form in our templates.
  *
  * @param FormInterface $form
  *
  * @return \Symfony\Component\Form\FormView
  */
 public function createFormView(FormInterface $form)
 {
     $post = $this->eavManager->initializeEntity($form->getSchema());
     $form = $this->formFactory->create(PostType::class, $post, ['form_id' => $form->getId()]);
     return $form->createView();
 }