1

Let me explain my situation. I have in D7

  1. 4 different taxonomy list. Each taxonomy list is connected to other data in the system
  2. A content type cFoo
  3. 2 different roles : contentmanager (CM) and user. hhahaha what else is new :-)

The CM is creating a entityque based on taxonomy terms which will result in let's say: tlist.

The user should select for an cFoo a term from tlist but if he used a term already in another cFoo he may not select it again.

I did testing and research but do not get the complete puzzle complete... I thought about the following solution for the user.

Build a webform with a selectbox with values of tlist. Contextual reference to this form will be cFoo.nid. Before loading this list in the webform it should already be filtered. Let say we have another view with terms already used named tListUsed. After the webform I will implement a rule to submit the selected term to the cFoo.

So now I have two views. tList, tListUsed. The basic question was: How to filter tList with view tListUsed?

UPDATED QUESTION
With the help of flags modules and views_exclude_previous modules i do not got this problem working. There is a approach on: https://www.youtube.com/watch?v=cQrw7Ydo1to which I now try to implement.

The strategy is now as follows: Load the list of tListused into a global var. Use this var as a contextual filter with multi values to exclude.

On which hook should I execute the building of tListUsed. It cannot be in the view itself as it is a filter to the view.

ps: question edited as setting up the tList for the CM is working and after trying some modules.

7
  • The missing puzzle piece is the flag module. You can flag terms per user and filter your view to not include them. Let me know if you require a full answer. Jul 15, 2016 at 13:53
  • I understand the flag module and understand that I can make flag list. But still then how to substract tList -flaglist within views. Currently instead of a flag list I have also a view with the terms already used by this user. In both cases I cannot see where to do the filtering..
    – Justme
    Jul 15, 2016 at 14:03
  • In your entity queue view, add the flag as a relationship, don't click "include.." and in your normal filters on the left, you can add a flag filter for "not flagged". Just tested this with an entity reference view + entity reference field and it works fine. I presume EntityQueue will be the same from the module description. i.imgur.com/zXMilT1.png Jul 15, 2016 at 14:33
  • I tried the flag module but did not get it working as well as views_exclude_previous. I guess I have to write a custom hook.
    – Justme
    Aug 19, 2016 at 13:46
  • I can't believe I'm typing this but.. If you don't want to write a hook and the flags work apart from that extra module.. You could possibly wrap your views rows in <div id="node_id_[nid]">Fields</div> using replacement patterns and use jQuery to remove duplicate IDs. stackoverflow.com/questions/15759882/… Aug 19, 2016 at 14:40

1 Answer 1

0

For those who need to implement this as well. I solved this by the following code. However in this code $tid_to_remove is not a view but generated on the view itself.

function MODULENAME_views_post_execute(&$view){

  switch ($view->name){
  case "VIEW_MACHINE_NAAM";

    GLOBAL $user;

    // Go through the view and build a list of items which should be removed
    $data = $view->result;
    $tid_to_remove = array();
    foreach ($data as $row => $rowinfo) {
      if ($rowinfo->users_node_uid == $user->uid ){     // if the current row belongs to the current user
        $tid_to_remove[] = $rowinfo->tid;  // added to the array
      }
    }

    // Optimize the array to unique values
    $tid_to_remove = array_unique($tid_to_remove);

    // Go through the view again en remove all values which are stored in $tid_to_remove
    $data = $view->result;
    foreach ($data as $row => $rowinfo) {
      if (in_array($rowinfo->tid,$tid_to_remove)){
        unset ($data[$row]);
      }
    }

    // place the values back into the view
    $view->result = $data;

  break;
  }
}

Your Answer

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

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