/** * {@inheritdoc} */ public function getNodeTranslationOr404(Request $request) { if (null !== ($route = $this->getRoute($request))) { if (null !== ($translation = $this->nodeTranslationManager->findTranslationByRoute($route))) { return $translation; } } throw new NotFoundHttpException('Not found node translation!'); }
public function testGetNodeOr404() { $node = $this->getMock('Tadcka\\Component\\Tree\\Model\\Node'); $nodeTranslation = $this->getMock('Tadcka\\Component\\Tree\\Model\\NodeTranslation'); $nodeTranslation->expects($this->any())->method('isOnline')->willReturn(true); $nodeTranslation->expects($this->any())->method('getNode')->willReturn($node); $this->nodeTranslationManager->expects($this->any())->method('findTranslationByRoute')->willReturn($nodeTranslation); $this->assertEquals($node, $this->pageNodeProvider->getNodeOr404($this->createRequest())); }
/** * Create backend node translation. * * @param NodeInterface $node * @param string $title * @param string $locale * * @return NodeTranslationInterface */ private function createBackendNodeTranslation(NodeInterface $node, $title, $locale) { $translation = $this->nodeTranslationManager->create(); $translation->setLang($locale); $translation->setNode($node); $translation->setTitle($title); $this->nodeTranslationManager->add($translation); return $translation; }
/** * On success. * * @param string $locale * @param NodeInterface $node * * @return string */ public function onSuccess($locale, NodeInterface $node) { $this->eventDispatcher->dispatch(TadckaTreeEvents::NODE_EDIT_SUCCESS, new TreeNodeEvent($locale, $node)); $this->nodeTranslationManager->save(); return $this->translator->trans('success.node_redirect_route_save', array(), 'TadckaSitemapBundle'); }