/** * Transforms an object (article) to a string (id). * * @param ArticleInterface|string $article * * @return string */ public function transform($article) { if (null === $article) { return; } if (!$article instanceof ArticleInterface) { throw new UnexpectedTypeException($article, ArticleInterface::class); } return $article->getId(); }
public function it_should_transform_package_to_article(PackageInterface $package, ArticleFactoryInterface $articleFactory, ArticleInterface $article) { $package->getHeadline()->willReturn('headline'); $package->getSlugline()->willReturn('slug'); $package->getLanguage()->willReturn('en'); $article->getTitle()->willReturn('headline'); $article->getSlug()->willReturn('slug'); $article->getLocale()->willReturn('en'); $articleFactory->createFromPackage($package)->willReturn($article); $this->transform($package)->shouldReturn($article); }
/** * {@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; }
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_unpublish_published_article(ArticleInterface $article) { $article->setStatus(ArticleInterface::STATUS_UNPUBLISHED)->shouldBeCalled(); $article->setPublishedAt(Argument::type('\\DateTime'))->shouldNotBeCalled(); $article->setPublishable(false)->shouldBeCalled(); $article->getPublishStartDate()->shouldBeCalled(); $article->getPublishEndDate()->shouldBeCalled(); $this->unpublish($article, ArticleInterface::STATUS_UNPUBLISHED)->shouldReturn($article); }
/** * @param ArticleInterface $article * @param ArticleMediaInterface $articleMedia */ private function replaceBodyImagesWithMedia(ArticleInterface $article, ArticleMediaInterface $articleMedia) { $body = $article->getBody(); $mediaId = $articleMedia->getKey(); preg_match("/(<!-- EMBED START Image {id: \"{$mediaId}\"} -->)(.+?)(<!-- EMBED END Image {id: \"{$mediaId}\"} -->)/im", str_replace(PHP_EOL, '', $body), $embeds); if (empty($embeds)) { return; } $figureString = $embeds[2]; $crawler = new Crawler($figureString); $images = $crawler->filter('figure img'); /** @var \DOMElement $imageElement */ foreach ($images as $imageElement) { foreach ($articleMedia->getRenditions() as $rendition) { if (strpos($imageElement->getAttribute('src'), $rendition->getImage()->getAssetId()) !== false) { $attributes = $imageElement->attributes; while ($attributes->length) { $imageElement->removeAttribute($attributes->item(0)->name); } $imageElement->setAttribute('src', $this->mediaManager->getMediaUri($rendition->getImage())); $imageElement->setAttribute('data-media-id', $mediaId); $imageElement->setAttribute('data-image-id', $rendition->getImage()->getAssetId()); } } } $article->setBody(str_replace($figureString, $crawler->filter('body')->html(), $body)); }
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'); }
/** * {@inheritdoc} */ public function getRouteForArticle(ArticleInterface $article) { return $article->getRoute(); }
private function reactOnStatusChange($originalArticleStatus, ArticleInterface $article) { $newArticleStatus = $article->getStatus(); if ($originalArticleStatus === $newArticleStatus) { return; } $articleService = $this->container->get('swp.service.article'); switch ($newArticleStatus) { case ArticleInterface::STATUS_PUBLISHED: $articleService->publish($article); break; default: $articleService->unpublish($article, $newArticleStatus); break; } }