/** * Checks if the passed value is valid. * * @param NodeInterface $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { $result = $this->repository->hasOtherNodeWithSameParentAndOrder($value->getParentId(), $value->getOrder(), $value->getNodeId(), $value->getSiteId()); if (true === $result) { $this->context->buildViolation($constraint->message)->addViolation(); } }
/** * Checks if a dynamic route pattern isn't in menu * * @param NodeInterface $value The value that should be validated * @param Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint) { if ($value->isInMenu() || $value->isInFooter()) { if (preg_match('/{.*}/', $value->getRoutePattern())) { $this->context->buildViolation($constraint->message)->atPath('routePattern')->addViolation(); } } }
/** * @param $node NodeInterface * @param string $areaId * * @return null|AreaInterface */ public function findAreaInNodeByAreaId(NodeInterface $node, $areaId) { foreach ($node->getAreas() as $key => $area) { if ($areaId === $key) { return $area; } } return null; }
/** * @param NodeInterface $node */ public function restore($node) { $nodes = $this->nodeRepository->findByNodeAndSite($node->getNodeId(), $node->getSiteId()); /** @var NodeInterface $node */ foreach ($nodes as $node) { $node->setDeleted(false); } $this->eventDispatcher->dispatch(NodeEvents::NODE_RESTORE, new NodeEvent($node)); }
/** * @param NodeInterface $node * @param Constraint $constraint */ public function validate($node, Constraint $constraint) { if ($node->getNodeType() === NodeInterface::TYPE_DEFAULT && $node->getNodeId() !== NodeInterface::ROOT_NODE_ID) { $parentId = $node->getParentId(); $parent = $this->nodeRepository->findOneByNodeId($parentId); if (null === $parent || $parent->isDeleted()) { $nameParent = null === $parent ? '' : $parent->getName(); $this->context->buildViolation($constraint->message)->setParameters(array('%nodeparent%' => $nameParent))->addViolation(); } } }
/** * Checks if the passed value is valid. * * @param NodeInterface $value The value that should be validated * @param Constraint $constraint The constraint for the validation */ public function validate($value, Constraint $constraint) { $nodesSameRoute = $this->nodeRepository->findByParentAndRoutePattern($value->getParentId(), $value->getRoutePattern(), $value->getNodeId(), $value->getSiteId()); if (0 < count($nodesSameRoute)) { $nodesSameRoute = current($nodesSameRoute); $message = $constraint->message; if (true === $nodesSameRoute->isDeleted()) { $message = $constraint->messageWitNodeDeleted; } $this->context->buildViolation($message, array("%nodeName%" => $nodesSameRoute->getName()))->atPath('routePattern')->addViolation(); } }
/** * Vote for $action on $node not owned by $user * A user can act on someone else's node if he has the matching super role and the node is in his perimeter * * @param string $action * @param NodeInterface $node * @param UserInterface $user * * @return bool */ protected function voteForSomeoneElseSubject($action, $node, UserInterface $user) { $requiredRole = ContributionRoleInterface::NODE_CONTRIBUTOR; switch ($action) { case ContributionActionInterface::EDIT: $requiredRole = ContributionRoleInterface::NODE_SUPER_EDITOR; break; case ContributionActionInterface::DELETE: $requiredRole = ContributionRoleInterface::NODE_SUPER_SUPRESSOR; break; } return $user->hasRole($requiredRole) && $this->isSubjectInPerimeter($node->getPath(), $user, NodeInterface::ENTITY_TYPE); }
/** * @param NodeInterface $node * * @return array */ protected function getStatusChoices(NodeInterface $node) { $choices = array(); $transitions = $node->getStatus()->getFromRoles(); foreach ($transitions as $transition) { $status = $transition->getToStatus(); // Adding original status if (empty($choices)) { $choices[] = $transition->getFromStatus(); } if ($this->authorizeStatusChangeManager->isGranted($node, $status)) { $choices[] = $status; } } return $choices; }
/** * @param NodeInterface $node */ protected function deleteRedirectionForNodeTree(NodeInterface $node) { $this->redirectionManager->deleteRedirection($node->getNodeId(), $node->getLanguage(), $node->getSiteId()); $nodes = $this->nodeRepository->findByParent($node->getNodeId(), $node->getSiteId()); foreach ($nodes as $node) { $this->deleteRedirectionForNodeTree($node); } }
/** * @param NodeInterface $node * @param BlockNodePattern|Constraint $constraint */ public function validate($node, Constraint $constraint) { if ($node->getStatus() instanceof StatusInterface && $node->getStatus()->isPublished()) { $areas = $node->getAreas(); $routePattern = $node->getRoutePattern(); foreach ($areas as $area) { $blocks = $area->getBlocks(); foreach ($blocks as $block) { $blockLabel = $block->getLabel(); $parameters = $this->generateFormManager->getRequiredUriParameter($block); foreach ($parameters as $parameter) { if (false === strpos($routePattern, '{' . $parameter . '}')) { $this->context->buildViolation($constraint->message)->setParameters(array('%blockLabel%' => $blockLabel, '%parameter%' => $parameter))->atPath('routePattern')->addViolation(); } } } } } }
/** * @param ObjectManager $manager * @param NodeInterface $node */ protected function generateRouteNode(ObjectManager $manager, $node) { $site = $this->getReference('site3'); foreach ($site->getAliases() as $key => $alias) { if ($alias->getLanguage() == $node->getLanguage()) { $route = new RouteDocument(); $route->setName($key . '_' . $node->getId()); $route->setHost($alias->getDomain()); $scheme = $alias->getScheme(); $route->setSchemes($scheme); $route->setLanguage($node->getLanguage()); $route->setNodeId($node->getNodeId()); $route->setSiteId($site->getSiteId()); $route->setAliasId($key); $route->setPattern($node->getRoutePattern()); $manager->persist($route); } } }
/** * @param NodeInterface $node * * @return int */ public function countAreaRef(NodeInterface $node) { $areaRef = 0; foreach ($node->getBlocks() as $block) { $areaRef = $areaRef + count($block->getAreas()); } return $areaRef; }
/** * @param array $orderedNode * @param NodeInterface $node */ public function orderNodeChildren($orderedNode, NodeInterface $node) { $nodeId = $node->getNodeId(); foreach ($orderedNode as $position => $childNodeId) { $siteId = $this->contextManager->getCurrentSiteId(); $children = $this->nodeRepository->findByNodeAndSite($childNodeId, $siteId); $path = $node->getPath() . '/' . $childNodeId; /** @var NodeInterface $child */ foreach ($children as $child) { $child->setOrder($position); $child->setParentId($nodeId); $child->setPath($path); } $event = new NodeEvent($child); $this->eventDispatcher->dispatch(NodeEvents::PATH_UPDATED, $event); } }
/** * @param NodeInterface $node */ public function generateRedirectionForNode(NodeInterface $node) { $siteId = $node->getSiteId(); $this->deleteRedirection($node->getNodeId(), $node->getLanguage(), $siteId); $nodes = $this->nodeRepository->findPublishedSortedByVersion($node->getNodeId(), $node->getLanguage(), $siteId); if (count($nodes) > 0) { $lastNode = array_shift($nodes); $routePatterns = array($this->completeRoutePattern($lastNode->getParentId(), $node->getRoutePattern(), $node->getLanguage())); foreach ($nodes as $otherNode) { $oldRoutePattern = $this->completeRoutePattern($otherNode->getParentId(), $otherNode->getRoutePattern(), $otherNode->getLanguage()); if (!in_array($oldRoutePattern, $routePatterns)) { $this->createRedirection($oldRoutePattern, $node->getNodeId(), $node->getLanguage()); array_push($routePatterns, $oldRoutePattern); } } } }
/** * @param FacadeInterface $facade * @param NodeInterface $node * @param AreaInterface $area * @param string $areaId */ protected function addLinksFromNode(FacadeInterface $facade, NodeInterface $node, AreaInterface $area, $areaId) { $facade->addLink('_block_list', $this->generateRoute('open_orchestra_api_block_list_with_transverse', array('language' => $node->getLanguage()))); $facade->addLink('_self_update_block_position', $this->generateRoute('open_orchestra_api_area_update_block_position', array('nodeId' => $node->getNodeId(), 'language' => $node->getLanguage(), 'version' => $node->getVersion(), 'siteId' => $node->getSiteId()))); }
/** * @param NodeInterface $node * * @return FacadeInterface */ public function transformVersion($node) { $facade = $this->newFacade(); $facade->id = $node->getId(); $facade->nodeId = $node->getNodeId(); $facade->name = $node->getName(); $facade->version = $node->getVersion(); $facade->createdBy = $node->getCreatedBy(); $facade->updatedBy = $node->getUpdatedBy(); $facade->createdAt = $node->getCreatedAt(); $facade->updatedAt = $node->getUpdatedAt(); $facade->status = $this->getTransformer('status')->transform($node->getStatus()); return $facade; }
/** * @param string $message * @param NodeInterface $node */ protected function info($message, NodeInterface $node) { $this->logger->info($message, array('node_id' => $node->getNodeId(), 'node_version' => $node->getVersion(), 'node_language' => $node->getLanguage(), 'node_name' => $node->getName())); }