diff --git a/CHANGELOG-0.x.md b/CHANGELOG-0.x.md index ec4b9d9..0f5e2e1 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.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. diff --git a/README.md b/README.md index c5d0a1f..a02551e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/composer.json b/composer.json index fc258c6..e80f98e 100755 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Twig/NcrExtension.php b/src/Twig/NcrExtension.php index 6430b3b..0a53800 100644 --- a/src/Twig/NcrExtension.php +++ b/src/Twig/NcrExtension.php @@ -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']), @@ -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 @@ -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