1

A little advice please:

Users "follow" a content type Parent by using the method in this question. There is a content type Posts which has an Entity Reference to the Parent it is assigned to.

How do I go about creating a View which shows all Posts which the current user has "followed"?

I guess this could be done with Views Field View but that seems a little over-kill. There must be a simpler way of doing this, just with Views out-the-box, surely?

Update

See my answer. Please, please, if anybody has a better solution let me know!

0

Use Views PHP.

In Views

  • Format
    • Content
  • Filter Criteria
    • Content: Published
    • Content: Type (=Post)
    • Global: PHP (see below for code)

Code for Global: PHP -

$flag = flag_get_flag('follow_parent');

$post_nid = $data->nid;

$post = node_load($post_nid);

$field_parent = field_get_items('node',$post,'field_parents');

$parents_followeds = array();

foreach ($field_parents as $field_parent) {
  $parent_nid = $field_parent['target_id'];
  $followed = $flag->is_flagged($parent_nid);
  $parent_followeds[] = $followed;
}

return in_array(TRUE, $parent_followeds) ? FALSE : TRUE;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.