/**
  * @param NodeFormPersistEvent $event
  *
  * @throws \Exception
  */
 public function saveCategoryTree(NodeFormPersistEvent $event)
 {
     if (!$event->getForm()->getData() instanceof Taxonomy) {
         return;
     }
     $positionData = $event->getForm()->get('tabs')->get('general')->get('position')->getNormData();
     if ($positionData) {
         $entityName = 'ClasticNewsBundle:Category';
         $positionData = json_decode($positionData);
         $data = $event->getForm()->getData();
         $entityManager = $event->getEntityManager();
         /** @var NestedTreeRepository $repo */
         $repo = $entityManager->getRepository($entityName);
         $positionData->parent = intval($positionData->parent) ? $positionData->parent : 0;
         $data->setParent(null);
         if (intval($positionData->parent) > 0) {
             $data->setParent($entityManager->getReference($entityName, $positionData->parent));
         }
         $repo->persistAsFirstChild($data);
         if ($positionData->position) {
             $repo->moveDown($data, $positionData->position);
         }
         $entityManager->flush();
     }
 }
 public function persist(NodeFormPersistEvent $event)
 {
     /** @var Site $site */
     $site = $event->getForm()->getData();
     foreach ($this->originalUrls as $url) {
         if (false === $site->getUrls()->contains($url)) {
             $event->getEntityManager()->remove($url);
         }
     }
     $event->getEntityManager()->flush();
 }
 /**
  * @param NodeFormPersistEvent $event
  *
  * @throws \Exception
  */
 public function persist(NodeFormPersistEvent $event)
 {
     /** @var Proxy $data */
     $data = $event->getForm()->getData();
     $em = $event->getEntityManager();
     // remove the relationship between the tag and the Task
     foreach ($this->original as $domain) {
         if (false === $data->getDomains()->contains($domain)) {
             $em->remove($domain);
         }
     }
     $em->flush();
 }
 public function invalidateNode(NodeFormPersistEvent $event)
 {
     $node = $event->getNode();
     try {
         if (isset($node->alias)) {
             $url = $this->requestStack->getMasterRequest()->getSchemeAndHttpHost() . '/' . $node->alias->getAlias();
             $this->cacheManager->invalidatePath($url);
         }
         $this->cacheManager->invalidateRoute('clastic_front_detail', ['id' => $node->getId()]);
     } catch (UnsupportedProxyOperationException $e) {
         // It will expire at some point.
     }
 }