-1

I'm trying to show specific contents for specific users based on the taxonomy term.

Variables explanation:

webauth variable

I am using these variables to setup my PHP filter. $_SESSION['company']; This will return the company name of the user. This is tested works as required.

taxonomy variable

I'm trying to get the taxonomy name based on the array format from print_r($data); which looks like, $data->field_field_company[0]['rendered']['#markup'] this prints the taxonomy term present in the array[0]. I'm using a for loop to print all the taxonomy terms (which has a purpose).

What I'm trying to achieve?

When the SESSION variable matches with the Taxonomy variable, show specified user related taxonomy term content.

So that user having XYZ company can see the content, having taxonomy entity with XYZ term.

How am I trying to achieve it?

In view add PHP global Filter and in filter code I'm trying to add this code:

$length = count($data->field_field_company);
  for ($i=0; $i < $length; $i++) { 
  /** as I'm having multiple arrays I'm checking every array **/
    if(($_SESSION['company']) == ($data->field_field_company[$i]['rendered']['#markup'])) {
    /** above should be like if(xyz == xyz) **/
      return FALSE;
    }
  }
  return TRUE;

If this same code is written in Fields Global PHP It works fine.

<?php
  $length = count($data->field_field_company);
  for ($i=0; $i < $length; $i++) { 
    if(($_SESSION['company']) == ($data->field_field_company[$i]['rendered']['#markup']))
    echo "hi";
    }
?>

Why it doesn't work at all in the Filter criteria?

0

Found out that there is a dev version for the above issue, you may need to update if you are using the old module version.

look at the comment #38 in link below. https://www.drupal.org/project/views_php/issues/1222448#comment-9852925

Where you can get the updated version of this module. https://www.drupal.org/project/views_php

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.