0

I have a view that I need to filter based on the current logged in user, however a secondary entity reference is in-between the two. Pretty sure I need to add in PHP contextual filter code but not exactly sure what is needed.

Scenario:

  1. inventory has an entity reference to retail_location.
  2. retail_location has an entity reference to users.
  3. I need to display inventory based on the retail_location of the logged in user.

D7.

1 Answer 1

0

Was able to get it working using the following code, it does however only allow for one retail location, which is all I need for this scenario.

  global $user;
  $query = new EntityFieldQuery;
  $query->entityCondition('entity_type', 'node')
      ->entityCondition('bundle', 'rnm_principal')
      ->fieldCondition('field_principal_retailer', 'target_id', array($user->uid));
  $results = $query->execute();
  return current($results['node'])->nid;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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