From 81be13eecaaf4072a20f6cc3ab44ca7f4659b6d3 Mon Sep 17 00:00:00 2001 From: Greg Brown Date: Sun, 17 Feb 2019 13:20:08 -0800 Subject: [PATCH] Add optional namespace argument to all NcrExtension twig methods --- CHANGELOG-0.x.md | 4 ++++ src/Twig/NcrExtension.php | 38 +++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/CHANGELOG-0.x.md b/CHANGELOG-0.x.md index 45681ba..ec4b9d9 100644 --- a/CHANGELOG-0.x.md +++ b/CHANGELOG-0.x.md @@ -2,6 +2,10 @@ This changelog references the relevant changes done in 0.x versions. +## v0.3.12 +* Add optional namespace argument to all NcrExtension twig methods and pass through to NcrPreloader. + + ## v0.3.11 * Use `app_env` parameter if available instead of `kernel.environment`. diff --git a/src/Twig/NcrExtension.php b/src/Twig/NcrExtension.php index a9131b1..6430b3b 100644 --- a/src/Twig/NcrExtension.php +++ b/src/Twig/NcrExtension.php @@ -127,30 +127,32 @@ public function isNodePublished($node): bool } /** - * @param bool $andClear + * @param bool $andClear + * @param string $namespace * * @return Node[] */ - public function getPreloadedNodes(bool $andClear = true): array + public function getPreloadedNodes(bool $andClear = true, string $namespace = NcrPreloader::DEFAULT_NAMESPACE): array { - $nodes = $this->ncrPreloader->getNodes(); + $nodes = $this->ncrPreloader->getNodes(null, $namespace); if ($andClear) { - $this->ncrPreloader->clear(); + $this->ncrPreloader->clear($namespace); } return $nodes; } /** - * @param bool $andClear + * @param bool $andClear + * @param string $namespace * * @return Node[] */ - public function getPreloadedPublishedNodes(bool $andClear = true): array + public function getPreloadedPublishedNodes(bool $andClear = true, string $namespace = NcrPreloader::DEFAULT_NAMESPACE): array { - $nodes = $this->ncrPreloader->getPublishedNodes(); + $nodes = $this->ncrPreloader->getPublishedNodes($namespace); if ($andClear) { - $this->ncrPreloader->clear(); + $this->ncrPreloader->clear($namespace); } return $nodes; @@ -160,34 +162,40 @@ public function getPreloadedPublishedNodes(bool $andClear = true): array * Preloads a node so it can optionally be rendered later. * * @param NodeRef|MessageRef|string $ref + * @param string $namespace */ - public function preloadNode($ref): void + public function preloadNode($ref, string $namespace = NcrPreloader::DEFAULT_NAMESPACE): void { $nodeRef = $this->toNodeRef($ref); if (!$nodeRef instanceof NodeRef) { return; } - $this->ncrPreloader->addNodeRef($nodeRef); + $this->ncrPreloader->addNodeRef($nodeRef, $namespace); } /** * @param NodeRef[]|MessageRef[]|string[] $refs + * @param string $namespace */ - public function preloadNodes(array $refs = []): void + public function preloadNodes(array $refs = [], string $namespace = NcrPreloader::DEFAULT_NAMESPACE): void { foreach ($refs as $ref) { - $this->preloadNode($ref); + $this->preloadNode($ref, $namespace); } } /** * @param Message[] $messages Array of messages to extract NodeRefs from. * @param array $paths An associative array of ['field_name' => 'qname'], i.e. ['user_id', 'acme:user'] + * @param string $namespace */ - public function preloadEmbeddedNodes(array $messages, array $paths = []): void - { - $this->ncrPreloader->addEmbeddedNodeRefs($messages, $paths); + public function preloadEmbeddedNodes( + array $messages, + array $paths = [], + string $namespace = NcrPreloader::DEFAULT_NAMESPACE + ): void { + $this->ncrPreloader->addEmbeddedNodeRefs($messages, $paths, $namespace); } /**