/**
  * @return string
  */
 public function renderTagRss()
 {
     $rss = array();
     foreach ($this->tagManager->findBy(array('enabled' => true)) as $tag) {
         $rss[] = sprintf('<link href="%s" title="%s : %s" type="application/rss+xml" rel="alternate" />', $this->router->generate('sonata_news_tag', array('tag' => $tag->getSlug(), '_format' => 'rss'), UrlGeneratorInterface::ABSOLUTE_URL), $this->blog->getTitle(), $tag->getName());
     }
     return implode("\n", $rss);
 }
 public function testLoad()
 {
     $tag = $this->getMockBuilder('Sonata\\ClassificationBundle\\Model\\TagInterfacer')->setMethods(array('getId'))->disableOriginalConstructor()->getMock();
     $tag->expects($this->any())->method('getId')->will($this->returnValue(23));
     $this->tagManager->expects($this->any())->method('find')->with($this->equalTo('23'))->will($this->returnValue($tag));
     $block = $this->getMock('Sonata\\BlockBundle\\Model\\BlockInterface');
     $block->expects($this->any())->method('getSetting')->with($this->equalTo('tagId'))->will($this->returnValue(23));
     $block->expects($this->once())->method('setSetting')->with($this->equalTo('tagId'), $this->equalTo($tag));
     $blockService = $this->getMockForAbstractClass('Sonata\\ClassificationBundle\\Block\\Service\\AbstractTagsBlockService', array('block.service', $this->templating, $this->contextManager, $this->tagManager, $this->tagAdmin));
     $blockService->load($block);
 }
Example #3
0
 /**
  * @param TagInterface|int $id
  * @param TagInterface     $default
  *
  * @return TagInterface
  */
 protected final function getTag($id, TagInterface $default = null)
 {
     if ($id instanceof TagInterface) {
         return $id;
     }
     if (is_numeric($id)) {
         return $this->tagManager->find($id);
     }
     return $default;
 }
 /**
  * Write a tag, this method is used by both POST and PUT action methods.
  *
  * @param Request  $request Symfony request
  * @param int|null $id      A tag identifier
  *
  * @return FormInterface
  */
 protected function handleWriteTag($request, $id = null)
 {
     $tag = $id ? $this->getTag($id) : null;
     $form = $this->formFactory->createNamed(null, 'sonata_classification_api_form_tag', $tag, array('csrf_protection' => false));
     FormHelper::removeFields($request->request->all(), $form);
     $form->bind($request);
     if ($form->isValid()) {
         $tag = $form->getData();
         $this->tagManager->save($tag);
         $view = \FOS\RestBundle\View\View::create($tag);
         $serializationContext = SerializationContext::create();
         $serializationContext->setGroups(array('sonata_api_read'));
         $serializationContext->enableMaxDepthChecks();
         $view->setSerializationContext($serializationContext);
         return $view;
     }
     return $form;
 }