[SOLVED] Filter Array FlowQuery

Hey guys,

How can I filter a FlowQuery with an array.

In my “Blogmenu” I have an array in the NodeType properties like

"blogcategories": {
   "0": "42323a2b-1de8-431f-accd-73f88e142c5d",
   "1": "08c08d4d-00f6-4b04-b546-93586bbccdf8"

and in every “BlogPost” NodeType I have an array in which the categories are defined that looks like the above.

I get the BlogPosts in my Controller with a FlowQuery

$articles = (new FlowQuery(array($node)))->children('[instanceof Blog.Blog:BlogPost]')->context(array('workspaceName' => 'live'))->sort('_index', $sorting)->get();

Now I want to filter for the defined categories. I have tried it with

->filter('[blogcategories][blogcategories = '.$categories.']')

blogcategories = Categories in the BlogPost properties
$categories = Menu categories

Can you help me?

Hi Patric,

i think you will need something like this to filter NodyType properties (references array):

then you could write some fusion (after migration to neos 3.x):

${q(site).find('[instanceof Blog.Blog:BlogPost]').filter('[blogcategories *= "' + q(node).property('_identifier') + '"]').get()}

Thank you Christian!

I have tried this:

$articles = (new FlowQuery(array($node)))->children('[instanceof NeosRulez.Blog:BlogPost]')->context(array('workspaceName' => 'live'))->sort('_index', $sorting)->filter('[blogcategories *= "'.$categories.'"]')->get();

and I get this:
Notice: Array to string conversion in /data/releases/current/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/NeosRulez_Blog_Controller_BlogController.php line 55

Hi Patric,

yes because you tried to submit an array. But you could build your filter string in a for each loop:

    $filterString = '';
    foreach ($categories as $key => $category) {
        if ($filterString !== '') {
            $serchString .= ',';
        $filterString .= '[blogcategories *= "' . $category . '"]';
    $articles = (new FlowQuery(array($node)))->children('[instanceof NeosRulez.Blog:BlogPost]')->context(array('workspaceName' => 'live'))->sort('_index', $sorting)->filter($filterString)->get();

Hi Christian!

Thank you! I have already tried something similar, but I get the following error:

Warning: strpos() expects parameter 1 to be string, array given in /data/releases/current/Data/Temporary/Development/Cache/Code/Flow_Object_Classes/Neos_Eel_FlowQuery_Operations_Object_FilterOperation.php line 241

could you please give your code here?

Hi Christian!

Many thanks! http://bit.ly/2CDfky0

i can not see anything wrong, the only thing which is missing is the class FilterOperation.php which add another filter operator *=

see the example from lelesys, you only have to change the namespace to neos / fusion, should still be running in neos 3

in getPropertyPath you should add you blogcategories wich is a NodeType property from your Blog NodeType

in canEvaluate you should change to your Blog or Category NodeType so only this nodetype will be recognized for filtering

thats all

Hi Christian!

It works. Many thanks!


1 Like