/**
  * @inheritDoc
  */
 public function getFunctions()
 {
     return ['page_type_name' => new \Twig_SimpleFunction('page_type_name', function ($page) {
         if ($page instanceof HasNodeInterface) {
             $page = ClassLookup::getClass($page);
         } elseif ($page instanceof HasRefInterface) {
             $page = $page->getRefName();
         }
         return $this->contentType->getFriendlyName($page);
     })];
 }
 /**
  * @param PreUpdateEventArgs $eventArgs
  */
 public function preUpdate(PreUpdateEventArgs $eventArgs)
 {
     $entity = $eventArgs->getEntity();
     if ($this->prepareMedia($entity)) {
         // Hack ? Don't know, that's the behaviour Doctrine 2 seems to want
         // See : http://www.doctrine-project.org/jira/browse/DDC-1020
         $em = $eventArgs->getEntityManager();
         $uow = $em->getUnitOfWork();
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassLookup::getClass($entity)), $eventArgs->getEntity());
     }
 }
 private function getPrevNext(HasNodeInterface $page, $loop)
 {
     $class = ClassLookup::getClass($page);
     $id = $page->getId();
     if (false === isset($this->nav[$class][$id])) {
         $parent = $this->contentCategory->getParentCategory($page, true);
         $siblings = $this->siteTree->getChildren($parent, ['refName' => $class, 'depth' => 1]) ?: new UnknownNodeBranch();
         $this->nav[$class][$id] = $this->calculatePrevNext($siblings, $page, $loop);
     }
     return array_values($this->nav[$class][$id]);
 }
 /**
  * @param HasPageTemplateInterface $page The page
  *
  * @return PageTemplateConfiguration
  */
 public function findOrCreateFor(HasPageTemplateInterface $page)
 {
     $pageTemplateConfiguration = $this->repo->findFor($page);
     if (null === $pageTemplateConfiguration) {
         $pageTemplates = $this->reader->getPageTemplates($page);
         $names = array_keys($pageTemplates);
         $defaultPageTemplate = $pageTemplates[$names[0]];
         $pageTemplateConfiguration = new PageTemplateConfiguration();
         $pageTemplateConfiguration->setPageId($page->getId());
         $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
         $pageTemplateConfiguration->setPageTemplate($defaultPageTemplate->getName());
     }
     return $pageTemplateConfiguration;
 }
 /**
  * @param string         $ref
  * @param string         $name
  * @param Callable|mixed $default
  *
  * @return mixed
  */
 private function getValue($ref, $name, $default = null)
 {
     $refName = is_object($ref) ? ClassLookup::getClass($ref) : $ref;
     if (isset($this->configuration[$refName][$name])) {
         return $this->configuration[$refName][$name];
     }
     if (false === is_callable($default)) {
         return $default;
     }
     $page = is_string($ref) ? new $refName() : $ref;
     $result = $default($page);
     unset($page);
     $this->configuration[$refName][$name] = $result;
     return $result;
 }
 /**
  * @param HasNodeInterface $page
  * @param array $context
  *
  * @return mixed
  */
 public function getContextValue(HasNodeInterface $page, array $context)
 {
     $controllerClass = substr(str_replace('Entity', 'Controller', ClassLookup::getClass($page)), 0, -strlen('Page')) . 'Controller';
     if (false === class_exists($controllerClass)) {
         return [];
     }
     /** @var PageControllerInterface|ContainerAwareInterface $controller */
     $controller = new $controllerClass();
     if (false === $controller instanceof PageControllerInterface) {
         throw new \RuntimeException("{$controllerClass} needs to implement " . PageControllerInterface::class);
     }
     if ($controller instanceof ContainerAwareInterface) {
         $controller->setContainer($this->container);
     }
     return $controller->serviceAction($page, $context);
 }
 /**
  * @param PreUpdateEventArgs $eventArgs
  */
 public function preUpdate(PreUpdateEventArgs $eventArgs)
 {
     $entity = $eventArgs->getEntity();
     if ($this->prepareMedia($entity)) {
         // Hack ? Don't know, that's the behaviour Doctrine 2 seems to want
         // See : http://www.doctrine-project.org/jira/browse/DDC-1020
         $em = $eventArgs->getEntityManager();
         $uow = $em->getUnitOfWork();
         $uow->recomputeSingleEntityChangeSet($em->getClassMetadata(ClassLookup::getClass($entity)), $eventArgs->getEntity());
         // local media is soft-deleted or soft-delete is reverted
         $changeSet = $eventArgs->getEntityChangeSet();
         if (isset($changeSet['deleted']) && $entity->getLocation() === 'local') {
             $deleted = !$changeSet['deleted'][0] && $changeSet['deleted'][1];
             $reverted = $changeSet['deleted'][0] && !$changeSet['deleted'][1];
             if ($deleted || $reverted) {
                 $oldFileUrl = $entity->getUrl();
                 $newFileName = $reverted ? $entity->getOriginalFilename() : uniqid();
                 $newFileUrl = dirname($oldFileUrl) . '/' . $newFileName . '.' . pathinfo($oldFileUrl, PATHINFO_EXTENSION);
                 $entity->setUrl($newFileUrl);
                 $this->fileUrlMap[$newFileUrl] = $oldFileUrl;
             }
         }
     }
 }
 /**
  * Returns a unique id for the current page part
  *
  * @return string
  */
 public function getUniqueId()
 {
     return str_replace('\\', '', ClassLookup::getClass($this)) . $this->id;
     //TODO
 }
 /**
  * Create a search document for a page
  *
  * @param NodeTranslation  $nodeTranslation
  * @param Node             $node
  * @param NodeVersion      $publicNodeVersion
  * @param HasNodeInterface $page
  */
 protected function addPageToIndex(NodeTranslation $nodeTranslation, Node $node, NodeVersion $publicNodeVersion, HasNodeInterface $page)
 {
     $rootNode = $this->currentTopNode;
     if (!$rootNode) {
         // Fetch main parent of current node...
         $rootNode = $this->em->getRepository('KunstmaanNodeBundle:Node')->getRootNodeFor($node, $nodeTranslation->getLang());
     }
     $doc = array('root_id' => $rootNode->getId(), 'node_id' => $node->getId(), 'node_translation_id' => $nodeTranslation->getId(), 'node_version_id' => $publicNodeVersion->getId(), 'title' => $nodeTranslation->getTitle(), 'lang' => $nodeTranslation->getLang(), 'slug' => $nodeTranslation->getFullSlug(), 'page_class' => ClassLookup::getClass($page), 'created' => $this->getUTCDateTime($nodeTranslation->getCreated())->format(\DateTime::ISO8601), 'updated' => $this->getUTCDateTime($nodeTranslation->getUpdated())->format(\DateTime::ISO8601));
     if ($this->logger) {
         $this->logger->info('Indexing document : ' . implode(', ', $doc));
     }
     // Permissions
     $this->addPermissions($node, $doc);
     // Search type
     $this->addSearchType($page, $doc);
     // Analyzer field
     $this->addAnalyzer($nodeTranslation, $doc);
     // Parent and Ancestors
     $this->addParentAndAncestors($node, $doc);
     // Content
     $this->addPageContent($nodeTranslation, $page, $doc);
     // Add document to index
     $uid = 'nodetranslation_' . $nodeTranslation->getId();
     $this->addBoost($node, $page, $doc);
     $this->addCustomData($page, $doc);
     $this->documents[] = $this->searchProvider->createDocument($uid, $doc, $this->indexName, $this->indexType . '_' . $nodeTranslation->getLang());
 }
 /**
  * Get class name of object (ie. class name without namespace)
  *
  * @param mixed $object
  *
  * @return string
  */
 public static function getClassName($object)
 {
     $className = explode('\\', ClassLookup::getClass($object));
     return array_pop($className);
 }
 /**
  * @param HasNodeInterface $page
  *
  * @return integer
  */
 public function getNodeIdFor(HasNodeInterface $page)
 {
     $this->initNodeVersions();
     $refName = ClassLookup::getClass($page);
     $refId = $page->getId();
     $branch = array_reduce($this->branches, function (Branch $result = null, Branch $branch) use($refName, $refId) {
         return $refName === $branch->getRefName() && $refId === $branch->getRefId() ? $branch : $result;
     });
     return $branch ? $branch->getNodeId() : null;
 }
Пример #12
0
 /**
  * Find the seo information for the given entity
  *
  * @param AbstractEntity $entity
  *
  * @return Seo
  */
 public function findFor(AbstractEntity $entity)
 {
     return $this->findOneBy(array('refId' => $entity->getId(), 'refEntityName' => ClassLookup::getClass($entity)));
 }
 /**
  * @param mixed(Node|string) $nodeOrInternalName
  * @param string $language
  * @param string $templateName
  */
 public function setPageTemplate($nodeOrInternalName, $language, $templateName)
 {
     $node = $this->getNode($nodeOrInternalName);
     /** @var $translation NodeTranslation */
     $translation = $node->getNodeTranslation($language, true);
     /** @var HasPageTemplateInterface|EntityInterface $page */
     $page = $translation->getRef($this->em);
     /** @var PageTemplateConfigurationRepository $repo */
     $repo = $this->em->getRepository('KunstmaanPagePartBundle:PageTemplateConfiguration');
     $pageTemplateConfiguration = $repo->findFor($page);
     if ($pageTemplateConfiguration) {
         $pageTemplateConfiguration->setPageTemplate($templateName);
     } else {
         $pageTemplateConfiguration = new PageTemplateConfiguration();
         $pageTemplateConfiguration->setPageId($page->getId());
         $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
         $pageTemplateConfiguration->setPageTemplate($templateName);
     }
     $this->em->persist($pageTemplateConfiguration);
     $this->em->flush();
 }
Пример #14
0
 /**
  * Get class name of object (ie. class name without namespace)
  *
  * @param string|object $reference
  *
  * @return string
  */
 public static function getClassName($reference)
 {
     $reference = is_string($reference) ? $reference : ClassLookup::getClass($reference);
     $className = explode('\\', $reference);
     return array_pop($className);
 }
 /**
  * @covers Kunstmaan\UtilitiesBundle\Helper\ClassLookup::getClassName
  */
 public function testGetClassName()
 {
     $class = ClassLookup::getClassName(new DummyClass());
     $this->assertEquals('DummyClass', $class);
 }
 /**
  * Add type to the index document
  *
  * @param object $page
  * @param array  $doc
  *
  * @return array
  */
 protected function addSearchType($page, &$doc)
 {
     // Type
     $type = ClassLookup::getClassName($page);
     if ($page instanceof SearchTypeInterface) {
         $type = $page->getSearchType();
     }
     $doc['type'] = $type;
 }
 /**
  * Page type. It should be distinct among all pages. You may just return `self::class`
  *
  * @return string
  */
 public function getType()
 {
     return ClassLookup::getClass($this);
 }
Пример #18
0
 /**
  * Set reference entity
  *
  * @param AbstractEntity $entity
  *
  * @return AclChangeset
  */
 public function setRef(AbstractEntity $entity)
 {
     $this->setRefId($entity->getId());
     $this->setRefEntityName(ClassLookup::getClass($entity));
     return $this;
 }
Пример #19
0
 /**
  * @param HasNodeInterface $hasNode      The object to link to
  * @param string           $lang         The locale
  * @param BaseUser         $owner        The user
  * @param string           $internalName The internal name (may be null)
  *
  * @throws \InvalidArgumentException
  *
  * @return Node
  */
 public function createNodeFor(HasNodeInterface $hasNode, $lang, BaseUser $owner, $internalName = null)
 {
     $em = $this->getEntityManager();
     $node = new Node();
     $node->setRef($hasNode);
     if (!$hasNode->getId() > 0) {
         throw new \InvalidArgumentException("the entity of class " . $node->getRefEntityName() . " has no id, maybe you forgot to flush first");
     }
     $node->setDeleted(false);
     $node->setInternalName($internalName);
     $parent = $hasNode->getParent();
     if ($parent) {
         /* @var NodeVersion $parentNodeVersion */
         $parentNodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')->findOneBy(array('refId' => $parent->getId(), 'refEntityName' => ClassLookup::getClass($parent)));
         if ($parentNodeVersion) {
             $node->setParent($parentNodeVersion->getNodeTranslation()->getNode());
         }
     }
     if ($hasNode instanceof HiddenFromNavInterface) {
         $node->setHiddenFromNav($hasNode->isHiddenFromNav());
     }
     $em->persist($node);
     $em->flush();
     $em->refresh($node);
     $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->createNodeTranslationFor($hasNode, $lang, $node, $owner);
     return $node;
 }
 /**
  * Test if entity has pageparts for the specified context
  *
  * @param HasPagePartsInterface $page    The page
  * @param string                $context The context
  *
  * @return bool
  */
 public function hasPageParts(HasPagePartsInterface $page, $context = 'main')
 {
     $em = $this->getEntityManager();
     $pageClassname = ClassLookup::getClass($page);
     $sql = 'SELECT COUNT(pp.id) FROM KunstmaanPagePartBundle:PagePartRef pp
              WHERE pp.pageEntityname = :pageEntityname
                AND pp.pageId = :pageId
                AND pp.context = :context';
     return $em->createQuery($sql)->setParameter('pageEntityname', $pageClassname)->setParameter('pageId', $page->getId())->setParameter('context', $context)->getSingleScalarResult() != 0;
 }
 /**
  * Create a node translation for a given node
  *
  * @param HasNodeInterface $hasNode The hasNode
  * @param string           $lang    The locale
  * @param Node             $node    The node
  * @param BaseUser         $owner   The user
  *
  * @throws \InvalidArgumentException
  *
  * @return NodeTranslation
  */
 public function createNodeTranslationFor(HasNodeInterface $hasNode, $lang, Node $node, BaseUser $owner)
 {
     $em = $this->getEntityManager();
     $className = ClassLookup::getClass($hasNode);
     if (!$hasNode->getId() > 0) {
         throw new \InvalidArgumentException("The entity of class " . $className . " has no id, maybe you forgot to flush first");
     }
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setNode($node)->setLang($lang)->setTitle($hasNode->getTitle())->setOnline(false)->setWeight(0);
     $em->persist($nodeTranslation);
     $nodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')->createNodeVersionFor($hasNode, $nodeTranslation, $owner, null);
     $nodeTranslation->setPublicNodeVersion($nodeVersion);
     $em->persist($nodeTranslation);
     $em->flush();
     $em->refresh($nodeTranslation);
     $em->refresh($node);
     return $nodeTranslation;
 }
 /**
  * @param HasNodeInterface $hasNode
  *
  * @return NodeVersion
  */
 public function getNodeVersionFor(HasNodeInterface $hasNode)
 {
     return $this->findOneBy(array('refId' => $hasNode->getId(), 'refEntityName' => ClassLookup::getClass($hasNode)));
 }
 /**
  * Add a draft node version for a given node
  *
  * @param HasNodeInterface $hasNode The hasNode
  * @param string           $lang    The locale
  * @param Node             $node    The node
  * @param BaseUser         $owner   The user
  *
  * @throws \InvalidArgumentException
  *
  * @return NodeTranslation
  */
 public function addDraftNodeVersionFor(HasNodeInterface $hasNode, $lang, Node $node, BaseUser $owner)
 {
     $em = $this->getEntityManager();
     $className = ClassLookup::getClass($hasNode);
     if (!$hasNode->getId() > 0) {
         throw new \InvalidArgumentException("The entity of class " . $className . " has no id, maybe you forgot to flush first");
     }
     $nodeTranslation = $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->findOneBy(array('lang' => $lang, 'node' => $node));
     $nodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')->createNodeVersionFor($hasNode, $nodeTranslation, $owner, null, NodeVersion::DRAFT_VERSION);
     $em->refresh($nodeTranslation);
     $em->refresh($node);
     return $nodeTranslation;
 }
 private function getType()
 {
     return ClassLookup::getClass($this);
 }
 /**
  * @param HasNodeInterface $entity
  *
  * @return NodeVersion
  */
 public function setRef(HasNodeInterface $entity)
 {
     $this->setRefId($entity->getId());
     $this->setRefEntityName(ClassLookup::getClass($entity));
     return $this;
 }
 /**
  * @param int    $id        The node id
  * @param string $subaction The subaction (draft|public)
  *
  * @throws AccessDeniedException
  * @Route("/{id}/{subaction}", requirements={"_method" = "GET|POST", "id" = "\d+"}, defaults={"subaction" = "public"}, name="KunstmaanNodeBundle_nodes_edit")
  * @Template()
  *
  * @return RedirectResponse|array
  */
 public function editAction($id, $subaction)
 {
     $this->init();
     /* @var Node $node */
     $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
     $this->checkPermission($node, PermissionMap::PERMISSION_EDIT);
     $request = $this->getRequest();
     $tabPane = new TabPane('todo', $request, $this->container->get('form.factory'));
     $nodeTranslation = $node->getNodeTranslation($this->locale, true);
     if (!$nodeTranslation) {
         //try to find a parent node with the correct translation, if there is none allow copy.
         //if there is a parent but it doesn't have the language to copy to don't allow it
         $parentNode = $node->getParent();
         if ($parentNode) {
             $parentNodeTranslation = $parentNode->getNodeTranslation($this->locale, true);
             $parentsAreOk = false;
             if ($parentNodeTranslation) {
                 $parentsAreOk = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->hasParentNodeTranslationsForLanguage($node->getParent()->getNodeTranslation($this->locale, true), $this->locale);
             }
         } else {
             $parentsAreOk = true;
         }
         return $this->render('KunstmaanNodeBundle:NodeAdmin:pagenottranslated.html.twig', array('node' => $node, 'nodeTranslations' => $node->getNodeTranslations(true), 'copyfromotherlanguages' => $parentsAreOk));
     }
     $nodeVersion = $nodeTranslation->getPublicNodeVersion();
     $draftNodeVersion = $nodeTranslation->getNodeVersion('draft');
     /* @var HasNodeInterface $page */
     $page = null;
     $draft = $subaction == 'draft';
     $saveAsDraft = $request->get('saveasdraft');
     if (!$draft && !empty($saveAsDraft) || $draft && is_null($draftNodeVersion)) {
         // Create a new draft version
         $draft = true;
         $subaction = "draft";
         $page = $nodeVersion->getRef($this->em);
         $nodeVersion = $this->createDraftVersion($page, $nodeTranslation, $nodeVersion);
         $draftNodeVersion = $nodeVersion;
     } elseif ($draft) {
         $nodeVersion = $draftNodeVersion;
         $page = $nodeVersion->getRef($this->em);
     } else {
         if ($request->getMethod() == 'POST') {
             //Check the version timeout and make a new nodeversion if the timeout is passed
             $thresholdDate = date("Y-m-d H:i:s", time() - $this->container->getParameter("kunstmaan_node.version_timeout"));
             $updatedDate = date("Y-m-d H:i:s", strtotime($nodeVersion->getUpdated()->format("Y-m-d H:i:s")));
             if ($thresholdDate >= $updatedDate) {
                 $page = $nodeVersion->getRef($this->em);
                 if ($nodeVersion == $nodeTranslation->getPublicNodeVersion()) {
                     $this->get('kunstmaan_node.admin_node.publisher')->createPublicVersion($page, $nodeTranslation, $nodeVersion, $this->user);
                 } else {
                     $this->createDraftVersion($page, $nodeTranslation, $nodeVersion);
                 }
             }
         }
         $page = $nodeVersion->getRef($this->em);
     }
     $isStructureNode = $page->isStructureNode();
     $menubuilder = $this->get('kunstmaan_node.actions_menu_builder');
     $menubuilder->setActiveNodeVersion($nodeVersion);
     $menubuilder->setEditableNode(!$isStructureNode);
     // Building the form
     $propertiesWidget = new FormWidget();
     $pageAdminType = $page->getDefaultAdminType();
     if (!is_object($pageAdminType) && is_string($pageAdminType)) {
         $pageAdminType = $this->container->get($pageAdminType);
     }
     $propertiesWidget->addType('main', $pageAdminType, $page);
     $nodeAdminType = $node->getDefaultAdminType();
     if (!is_object($nodeAdminType) && is_string($nodeAdminType)) {
         $nodeAdminType = $this->container->get($nodeAdminType);
     }
     $propertiesWidget->addType('node', $nodeAdminType, $node);
     $tabPane->addTab(new Tab('Properties', $propertiesWidget));
     // Menu tab
     if (!$isStructureNode) {
         $menuWidget = new FormWidget();
         $menuWidget->addType('menunodetranslation', new NodeMenuTabTranslationAdminType(), $nodeTranslation);
         $menuWidget->addType('menunode', new NodeMenuTabAdminType(), $node);
         $tabPane->addTab(new Tab('Menu', $menuWidget));
         $this->get('event_dispatcher')->dispatch(Events::ADAPT_FORM, new AdaptFormEvent($request, $tabPane, $page, $node, $nodeTranslation, $nodeVersion));
     }
     $tabPane->buildForm();
     if ($request->getMethod() == 'POST') {
         $tabPane->bindRequest($request);
         if ($tabPane->isValid()) {
             $this->get('event_dispatcher')->dispatch(Events::PRE_PERSIST, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
             $nodeTranslation->setTitle($page->getTitle());
             if ($isStructureNode) {
                 $nodeTranslation->setSlug('');
             }
             $nodeVersion->setUpdated(new DateTime());
             if ($nodeVersion->getType() == 'public') {
                 $nodeTranslation->setUpdated($nodeVersion->getUpdated());
             }
             $this->em->persist($nodeTranslation);
             $this->em->persist($nodeVersion);
             $tabPane->persist($this->em);
             $this->em->flush();
             $this->get('event_dispatcher')->dispatch(Events::POST_PERSIST, new NodeEvent($node, $nodeTranslation, $nodeVersion, $page));
             $this->get('session')->getFlashBag()->add('success', 'The page has been edited');
             $params = array('id' => $node->getId(), 'subaction' => $subaction, 'currenttab' => $tabPane->getActiveTab());
             $params = array_merge($params, $tabPane->getExtraParams($request));
             return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', $params));
         }
     }
     $nodeVersions = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion')->findBy(array('nodeTranslation' => $nodeTranslation), array('updated' => 'ASC'));
     $queuedNodeTranslationAction = $this->em->getRepository('KunstmaanNodeBundle:QueuedNodeTranslationAction')->findOneBy(array('nodeTranslation' => $nodeTranslation));
     return array('page' => $page, 'entityname' => ClassLookup::getClass($page), 'nodeVersions' => $nodeVersions, 'node' => $node, 'nodeTranslation' => $nodeTranslation, 'draft' => $draft, 'draftNodeVersion' => $draftNodeVersion, 'subaction' => $subaction, 'tabPane' => $tabPane, 'editmode' => true, 'queuedNodeTranslationAction' => $queuedNodeTranslationAction);
 }
Пример #27
0
 public function postFlushBuild(Fixture $fixture)
 {
     $entities = $fixture->getAdditionalEntities();
     $fixtureParams = $fixture->getParameters();
     foreach ($fixture->getTranslations() as $language => $data) {
         /** @var HasNodeInterface $page */
         $page = $entities[$fixture->getName() . '_' . $language];
         /** @var NodeTranslation $translationNode */
         $translationNode = $entities['translationNode_' . $language];
         $pagecreator = array_key_exists('creator', $fixtureParams) ? $fixtureParams['creator'] : 'pagecreator';
         $creator = $this->userRepo->findOneBy(array('username' => $pagecreator));
         $nodeVersion = new NodeVersion();
         $nodeVersion->setNodeTranslation($translationNode);
         $nodeVersion->setType('public');
         $nodeVersion->setOwner($creator);
         $nodeVersion->setRef($page);
         $translationNode->setPublicNodeVersion($nodeVersion);
         if (isset($fixtureParams['template'])) {
             $pageTemplateConfiguration = new PageTemplateConfiguration();
             $pageTemplateConfiguration->setPageId($page->getId());
             $pageTemplateConfiguration->setPageEntityName(ClassLookup::getClass($page));
             $pageTemplateConfiguration->setPageTemplate($fixtureParams['template']);
             $this->manager->persist($pageTemplateConfiguration);
         }
         $this->manager->persist($nodeVersion);
         $this->manager->persist($translationNode);
     }
     $this->manager->flush();
 }
 /**
  * @param HasNodeInterface $page
  * @param bool             $full
  *
  * @invalidate cache on structure change
  * @return Category[]
  */
 public function getBreadcrumbs(HasNodeInterface $page, $full = false)
 {
     $key = sprintf('%s:%d:%d', ClassLookup::getClass($page), $page->getId(), $full);
     if ($this->cache->contains($key)) {
         return $this->cache->fetch($key);
     }
     $nodeTranslation = $this->nodeVersions->getNodeTranslationFor($page);
     if (null === $nodeTranslation) {
         throw new \RuntimeException(sprintf('Cant find node for %s:%d page', get_class($page), $page->getId()));
     }
     $lang = $nodeTranslation->getLang();
     $breadcrumbs = $this->breadCrumbsService->getNodePath($nodeTranslation->getNode());
     $parents = (new ArrayCollection($breadcrumbs))->filter(function (Node $node) use($full) {
         return $full || false === $node->isHiddenFromNav();
     })->map(function (Node $node) use($lang) {
         return $node->getNodeTranslation($lang, true);
     })->map(function (NodeTranslation $nt) {
         return $this->nodeTranslationToCategory($nt);
     })->toArray();
     $this->cache->save($key, $parents);
     return $parents;
 }
Пример #29
0
 /**
  * @param AbstractPagePart $pagepart
  *
  * @return string
  */
 public function getType(AbstractPagePart $pagepart)
 {
     $possiblePagePartTypes = $this->configurator->getPossiblePagePartTypes();
     foreach ($possiblePagePartTypes as &$pageparttype) {
         if ($pageparttype['class'] == ClassLookup::getClass($pagepart)) {
             return $pageparttype['name'];
         }
     }
     return "no name";
 }
 /**
  * @param HasPageTemplateInterface $page
  *
  * @return PageTemplateConfiguration
  */
 public function findFor(HasPageTemplateInterface $page)
 {
     return $this->findOneBy(array('pageId' => $page->getId(), 'pageEntityName' => ClassLookup::getClass($page)));
 }