Exemple #1
0
 public function createTemporary(TemplateInterface $template, Resource $parent = null, EavPersisterObjectInterface $object = null)
 {
     $context = $this->contextLanguageMediator->getContextManager()->getContext();
     $culture = $this->contextLanguageMediator->getLanguageManager()->getObject();
     $module = $template->getModule();
     /** @var EavPersisterObjectInterface $container */
     $container = $this->eavPersister->loadModel($module, $context, $object);
     $resource = new Resource();
     $resource->setExpireTemporaryDate(new \DateTime("+3 hour"));
     $resource->setContext($context);
     $resource->setTemplate($template);
     if ($parent) {
         $resource->setParent($parent);
     }
     $this->objectManager->persist($resource);
     $translation = new ResourceTranslation();
     $translation->setResource($resource);
     $translation->setLanguage($culture);
     $translation->setName(uniqid());
     $this->objectManager->persist($translation);
     $container->setResource($resource);
     $this->objectManager->persist($container);
     $this->objectManager->flush();
     return $resource;
 }
 /**
  * @param Template $template
  * @param Resource $parent
  * @return Resource
  */
 public function create(Template $template, Resource $parent = null, array $data)
 {
     $resource = new Resource();
     $resource->setTemplate($template);
     $this->objectManager->persist($resource);
     $translation = new ResourceTranslation();
     $translation->setResource($resource);
     $translation->setLanguage($this->language->getObject());
     $translation->setName(uniqid());
     $this->objectManager->persist($translation);
     $module = $template->getModule();
     $container = $this->loadModel($resource, $module);
     $moduleManager = $this->moduleManager->setModule($module);
     return $moduleManager->save($container, $data);
 }