Skip to content

Commit

Permalink
Added ezobjectrelationlilst_content operator
Browse files Browse the repository at this point in the history
  • Loading branch information
ThorFjelldalen committed Jan 7, 2021
1 parent 17e27a5 commit 8829f79
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
32 changes: 32 additions & 0 deletions classes/TemplateOperators/EzObjectRelationListContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
namespace Swark\TemplateOperators;

/**
* Alternative for getting ezobjectrelationlist content as a list of nodes, instead of an array which does not have the nodes.
*
* Examples:
* ```eztpl
* {$data_map.my_ezobjectrelationlist_field|ezobjectrelationlist_content} => array(Node)
* ```
*
* Will return the node directly, if only one is related.
*/
class EzObjectRelationListContent extends \SwarkOperator
{
function __construct()
{
parent::__construct('ezobjectrelationlist_content');
}

static function execute($ezSelectionField, $namedParameters)
{
$classContent = $ezSelectionField->attribute('content');
$relationList = $classContent['relation_list'];

$nodeIds = array_map(function($node) {
return $node['node_id'];
}, $relationList);

return \eZContentObjectTreeNode::fetch($nodeIds);
}
}
8 changes: 7 additions & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Operators
.. raw:: html

<hr />

.. include:: operators/is_post_request.rst

.. raw:: html
Expand Down Expand Up @@ -270,6 +270,12 @@ Operators

.. include:: operators/ezselection_content.rst

.. raw:: html

<hr />

.. include:: operators/ezobjectrelationlist_content.rst


Workflow event types
====================
Expand Down
37 changes: 37 additions & 0 deletions doc/operators/ezobjectrelationlist_content.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ezobjectrelationlist_content
-------------------

Summary
~~~~~~~
Alternative for getting ezobjectrelationlist content as a list of nodes, instead of an array which does not have the nodes.

Will return the node directly, if only one is related.

Usage
~~~~~
::

field|ezobjectrelationlist_content

Parameters
~~~~~~~~~~
.. list-table::
:header-rows: 1

* - Name
- Description
- Required
- Default

* - `field`
- eZObjectRelationList field from data_map. Do note that we do not pass in the content, and instead the entire field.
- Yes
-

Examples
~~~~~~~~
::

{$data_map.my_ezobjectrelationlist_field|ezobjectrelationlist_content}

Returns array of nodes, or the node directly: `array(eZContentObjectTreeNode)|eZContentObjectTreeNode`.
1 change: 1 addition & 0 deletions settings/swark.ini
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ OperatorMap[variable_names]=SwarkVariableNamesOperator
OperatorMap[get_scheme]=SwarkGetSchemeOperator
OperatorMap[url_modify]=Swark\TemplateOperators\UrlModifier
OperatorMap[ezselection_content]=Swark\TemplateOperators\EzSelectionContent
OperatorMap[ezobjectrelationlist_content]=Swark\TemplateOperators\EzObjectRelationListContent
OperatorMap[embed_design_file]=Swark\TemplateOperators\EmbedDesignFile
OperatorMap[dump]=Swark\TemplateOperators\DebugDump

0 comments on commit 8829f79

Please sign in to comment.