/** * Transforms an id to an object (route). * * @param string $routeId * * @return RouteInterface * * @throws TransformationFailedException if object (route) is not found */ public function reverseTransform($routeId) { $route = $this->routeProvider->getOneById($routeId); if (null === $route) { throw new TransformationFailedException(sprintf('Route with id "%s" does not exist!', $routeId)); } return $route; }
public function it_applies_rule(RuleInterface $rule, Article $subject, RouteProviderInterface $routeProvider, RouteInterface $route, LoggerInterface $logger, ArticleServiceInterface $articleService) { $rule->getConfiguration()->willReturn(['route' => 'some/route', 'templateName' => 'template.twig.html', 'published' => 'true']); $rule->getExpression()->willReturn('article.getSomething("something") matches /something/'); $routeProvider->getOneById('some/route')->willReturn($route); $subject->setRoute($route)->shouldBeCalled(); $subject->setTemplateName('template.twig.html')->shouldBeCalled(); $articleService->publish($subject)->shouldBeCalled(); $logger->info(Argument::any('string'))->shouldBeCalled(); $this->apply($rule, $subject)->shouldReturn(null); }
/** * @param PackageInterface $package * * @return ArticleInterface */ protected function hydrateArticle(PackageInterface $package) { /** @var ArticleInterface $article */ $article = $this->create(); $article->setBody($this->populateBody($package)); $article->setTitle($package->getHeadline()); if (null !== $package->getSlugline()) { $article->setSlug($package->getSlugline()); } $article->setLocale($package->getLanguage()); $article->setLead($this->populateLead($package)); $article->setMetadata($package->getMetadata()); // assign default route $article->setRoute($this->routeProvider->getRouteForArticle($article)); return $article; }
/** * {@inheritdoc} */ public function apply(RuleInterface $rule, RuleSubjectInterface $subject) { $configuration = $this->validateRuleConfiguration($rule->getConfiguration()); if (!$this->isAllowedType($subject) || empty($configuration)) { return; } /* @var ArticleInterface $subject */ if (isset($configuration['route'])) { $route = $this->routeProvider->getOneById($configuration['route']); if (null === $route) { $this->logger->warning('Route not found! Make sure the rule defines an existing route!'); return; } $subject->setRoute($route); } $subject->setTemplateName($configuration['templateName']); if ((bool) $configuration['published']) { $this->articleService->publish($subject); } $this->logger->info(sprintf('Configuration: "%s" for "%s" rule has been applied!', json_encode($configuration), $rule->getExpression())); }
/** * Load meta object by provided type and parameters. * * @MetaLoaderDoc( * description="Article Loader loads articles from Content Repository", * parameters={ * contentPath="SINGLE|required content path", * slug="SINGLE|required content slug", * pageName="COLLECTiON|name of Page for required articles" * } * ) * * @param string $type object type * @param array $parameters parameters needed to load required object type * @param int $responseType response type: single meta (LoaderInterface::SINGLE) or collection of metas (LoaderInterface::COLLECTION) * * @return Meta|Meta[]|bool false if meta cannot be loaded, a Meta instance otherwise * * @throws \Exception */ public function load($type, $parameters = [], $responseType = LoaderInterface::SINGLE) { $criteria = new Criteria(); if ($responseType === LoaderInterface::SINGLE) { if (array_key_exists('article', $parameters) && $parameters['article'] instanceof ArticleInterface) { $this->dm->detach($parameters['article']); $criteria->set('id', $parameters['article']->getId()); } elseif (array_key_exists('slug', $parameters)) { $criteria->set('slug', $parameters['slug']); } try { return $this->getArticleMeta($this->articleProvider->getOneByCriteria($criteria)); } catch (NotFoundHttpException $e) { return; } } elseif ($responseType === LoaderInterface::COLLECTION) { $currentPage = $this->context->getCurrentPage(); $route = null; if (null !== $currentPage) { $route = $currentPage->getValues(); } if (array_key_exists('route', $parameters)) { if (null === $route || $route instanceof RouteInterface && $route->getId() !== $parameters['route']) { if (is_int($parameters['route'])) { $route = $this->routeProvider->getOneById($parameters['route']); } elseif (is_string($parameters['route'])) { $route = $this->routeProvider->getOneByStaticPrefix($parameters['route']); } } } if ($route instanceof RouteInterface) { $criteria->set('route', $route); } else { return; } $criteria = $this->applyPaginationToCriteria($criteria, $parameters); $articles = $this->articleProvider->getManyByCriteria($criteria); if ($articles->count() > 0) { $metaCollection = new MetaCollection(); $metaCollection->setTotalItemsCount($this->articleProvider->getCountByCriteria($criteria)); foreach ($articles as $article) { $articleMeta = $this->getArticleMeta($article); if (null !== $articleMeta) { $metaCollection->add($articleMeta); } } unset($articles, $route, $criteria); return $metaCollection; } } return; }
public function it_creates_article_from_package_and_sets_article_slug_from_package_slugline(FactoryInterface $factory, PackageInterface $package, Article $article, RouteInterface $route, RouteProviderInterface $routeProvider) { $factory->create()->willReturn($article); $item = new Item(); $item->setBody('some item body'); $item->setType('text'); $item->setDescription('item lead'); $package->getHeadline()->shouldBeCalled()->willReturn('item headline'); $package->getDescription()->shouldBeCalled()->willReturn('package lead'); $package->getBody()->shouldBeCalled()->willReturn('some package body'); $package->getItems()->shouldBeCalled()->willReturn(new ArrayCollection([$item])); $package->getLanguage()->shouldBeCalled()->willReturn('en'); $package->getMetadata()->shouldBeCalled()->willReturn(['some' => 'meta']); $package->getSlugline()->shouldBeCalled()->willReturn('slugline'); $article->setTitle('item headline')->shouldBeCalled(); $article->setBody('some package body some item body')->shouldBeCalled(); $article->setLead('package lead item lead')->shouldBeCalled(); $article->setLocale('en')->shouldBeCalled(); $article->setRoute($route)->shouldBeCalled(); $article->setMetadata(['some' => 'meta'])->shouldBeCalled(); $article->setSlug('slugline')->shouldBeCalled(); $routeProvider->getRouteForArticle($article)->willReturn($route); $this->createFromPackage($package)->shouldReturn($article); }
public function it_should_reverse_transform_id_to_route(RouteProviderInterface $routeProvider, RouteInterface $route) { $routeProvider->getOneById('some-id')->willReturn($route); $this->reverseTransform('some-id')->shouldReturn($route); }
public function it_should_build_form(FormBuilderInterface $builder, RouteProviderInterface $routeProvider) { $builder->addModelTransformer(new RouteToIdTransformer($routeProvider->getWrappedObject()))->shouldBeCalled(); $this->buildForm($builder, []); }