/**
  * {@inheritdoc}
  */
 public function resolveFromArticle(ArticleInterface $article, $templateName = TemplateNameResolverInterface::TEMPLATE_NAME)
 {
     /** @param $route RouteInterface */
     if (null !== ($route = $article->getRoute())) {
         if (null !== $route->getTemplateName()) {
             $templateName = $route->getTemplateName();
         }
         if (RouteInterface::TYPE_COLLECTION === $route->getType() && null !== $route->getArticlesTemplateName()) {
             $templateName = $route->getArticlesTemplateName();
         }
     }
     if (null !== $article->getTemplateName()) {
         $templateName = $article->getTemplateName();
     }
     return $templateName;
 }
Ejemplo n.º 2
0
 public function it_should_set_template_name(Route $route, ArticleInterface $article)
 {
     $this->setTemplateName(null, [])->shouldReturn([]);
     $this->setTemplateName(null, [RouteObjectInterface::ROUTE_OBJECT => $route])->shouldReturn([RouteObjectInterface::ROUTE_OBJECT => $route, RouteObjectInterface::TEMPLATE_NAME => 'article.html.twig']);
     $route->getTemplateName()->willReturn('test.html.twig');
     $route->getContent()->willReturn(null);
     $route->getType()->willReturn(RouteInterface::TYPE_CONTENT);
     $this->setTemplateName(null, [RouteObjectInterface::ROUTE_OBJECT => $route])->shouldReturn([RouteObjectInterface::ROUTE_OBJECT => $route, RouteObjectInterface::TEMPLATE_NAME => 'test.html.twig']);
     $route->getTemplateName()->willReturn('test.html.twig');
     $route->getType()->shouldBeCalled();
     $article->getRoute()->willReturn($route);
     $article->getTemplateName()->willReturn(null);
     $this->setTemplateName($article, [RouteObjectInterface::ROUTE_OBJECT => $route])->shouldReturn([RouteObjectInterface::ROUTE_OBJECT => $route, RouteObjectInterface::TEMPLATE_NAME => 'test.html.twig']);
     $route->getTemplateName()->willReturn('test.html.twig');
     $article->getRoute()->willReturn($route);
     $article->getTemplateName()->willReturn('article2.html.twig');
     $this->setTemplateName($article, [])->shouldReturn([RouteObjectInterface::TEMPLATE_NAME => 'article2.html.twig']);
 }
 public function it_should_resolve_template_name_from_collection_type_route_and_defaultArticlesTemplate_set_and_defaultTemplate_in_article_(Route $route, ArticleInterface $article)
 {
     $route->getType()->willReturn(RouteInterface::TYPE_COLLECTION);
     $route->getTemplateName()->willReturn('test2.html.twig');
     $route->getArticlesTemplateName()->willReturn('article_template.html.twig');
     $article->getRoute()->willReturn($route);
     $article->getTemplateName()->willReturn('custom_article.html.twig');
     $this->resolve($article)->shouldReturn('custom_article.html.twig');
 }