Skip to content

Commit

Permalink
Add optional namespace argument to all NcrExtension twig methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbrown committed Feb 17, 2019
1 parent 81ee00a commit 81be13e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-0.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
38 changes: 23 additions & 15 deletions src/Twig/NcrExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 81be13e

Please sign in to comment.