/**
  * Checks if the passed value is valid.
  *
  * @param mixed      $value      The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  *
  * @api
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof Node) {
         $this->context->addViolation('Attempt to validate non Node entity');
         return;
     }
     $uow = $this->entityManager->getUnitOfWork();
     $originalData = $uow->getOriginalEntityData($value);
     // If we've been given a custom path, then don't use nonConflict in route path generation
     $hasCustomPath = strlen($value->getPath());
     $route = $this->routeBuilder->build($value, !$hasCustomPath);
     $routeName = $this->routeBuilder->buildRouteName($route->getPath());
     if (is_array($originalData) && count($originalData)) {
         if ($originalData['path'] !== $value->getPath()) {
             $existingRoute = $this->entityManager->getRepository('CmfRoutingBundle:Route')->findOneByName($routeName);
             if ($existingRoute instanceof Route) {
                 $this->context->buildViolation("A page at path '{$route->getPath()}' already exists")->atPath('path')->addViolation();
                 return;
             }
         } elseif ($value->getRoute() instanceof Route && $value->getRoute()->getName() !== $routeName) {
             $existingRoute = $this->entityManager->getRepository('CmfRoutingBundle:Route')->findOneByName($routeName);
             if ($existingRoute instanceof Route) {
                 $this->context->buildViolation("A page at path '{$route->getPath()}' already exists")->atPath('path')->addViolation();
                 return;
             }
         }
     }
 }
 /**
  * Create a 200 route for a new FieldableEntity
  *
  * @param FieldableEntity $entity
  *
  * @return Route
  */
 protected function getEntityRoute(FieldableEntity $entity)
 {
     return $this->routeBuilder->build($entity);
 }
 /**
  * Create a 200 route for a new Node
  *
  * @param Node $node
  *
  * @return Route
  */
 protected function getNodeRoute(Node $node)
 {
     return $this->routeBuilder->build($node);
 }