Skip to content

Commit

Permalink
Add NcrExtension::derefNodes and twig function ncr_deref_nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbrown committed Feb 26, 2019
1 parent 81be13e commit 8aedccb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
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.13
* Add `NcrExtension::derefNodes` and twig function `ncr_deref_nodes`.


## v0.3.12
* Add optional namespace argument to all NcrExtension twig methods and pass through to NcrPreloader.

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ Here is the creator:

__Other twig functions (documentation wip):__

+ ncr_deref_nodes
+ ncr_get_preloaded_nodes
+ ncr_get_preloaded_published_nodes
+ ncr_preload_node
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"require": {
"php": ">=7.1",
"gdbots/ncr": "~0.2",
"gdbots/ncr": "^0.3.14 || ~0.4",
"gdbots/pbjx-bundle": "~0.3"
},
"require-dev": {
Expand Down
21 changes: 21 additions & 0 deletions src/Twig/NcrExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function __construct(
public function getFunctions()
{
return [
new \Twig_SimpleFunction('ncr_deref_nodes', [$this, 'derefNodes']),
new \Twig_SimpleFunction('ncr_get_node', [$this, 'getNode']),
new \Twig_SimpleFunction('ncr_get_preloaded_nodes', [$this, 'getPreloadedNodes']),
new \Twig_SimpleFunction('ncr_get_preloaded_published_nodes', [$this, 'getPreloadedPublishedNodes']),
Expand All @@ -73,6 +74,24 @@ public function getName()
return 'gdbots_ncr_extension';
}

/**
* @see NcrCache::derefNodes
*
* @param Node $node
* @param array $fields
* @param string $return
*
* @return array
*/
public function derefNodes($node, array $fields = [], ?string $return = null): array
{
if (!$node instanceof Node) {
return [];
}

return $this->ncrCache->derefNodes($node, $fields, $return);
}

/**
* Gets a node from the NcrCache service if it's available.
* This will NOT make a new request to fetch a node, it must
Expand Down Expand Up @@ -186,6 +205,8 @@ public function preloadNodes(array $refs = [], string $namespace = NcrPreloader:
}

/**
* @see NcrPreloader::addEmbeddedNodeRefs
*
* @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
Expand Down

0 comments on commit 8aedccb

Please sign in to comment.