I have a content type Project with an entityreference user field field_project_team where you can assign users to the project.

I also have a content type Task with an entityreference field field_parent_project pointing to its parent Project and an entityreference user field field_responsible where you can choose one of users to be responsible for this Task.

I want the Task field options to include only those users who are mentioned in field_project_team of the parent node.

I've created a user type view with entityreference display for this, where I want to filter users by their belonging to field_project_team of the project with nid from field_parent_project, but can't configure it correctly.

What i'm actually trying to do:
1) When you create a Project node, you can select users who will be a working team for this very project. I've already done it with a field_project_team - an entityreference user select list, which selects users with the role I need via user view with entityreference display.
2) You can create Task nodes for each Project. Each Task node should be connected to its parent Project. I'm doing it like this: on a Project node page I have a button "Add task" which opens Task node add page via the link like node/add/task/[xxx] (where [xxx] is a nid of the parent Project node). Then in the Task content type i have an entityreference field field_parent_project which is prepopulated from URL, so I can get the parent node reference filled automaticly when adding a new task.

All above mantioned works fine, but i try to achive one more thing:
3) When adding/etiting a Task node you should be able to assing this very task to some users to make them responsible for performing this task. In the Task content type I have an entityreference user select field called field_responsible where you can select users. But I want to see in this field not all site users, but only those who are already selected as a Project team - in the field_project_team of the parent Project. To get such a filtered user list I've changed the field_responsible settings ENTITY SELECTION mode to Views: filter by an entity reference view and created a user view with Entity Reference display called "Project team users" to filter users.

My problem is that I can't configure the display in a right way to get only those users I need, i.e. those who are already selected to be a Project team of a parent Project referenced from a Task via field_parent_project field.

This is my View display: enter image description here

And some explaination:
1. A bridge to the Content entity that is referencing User via field_responsible
2. A bridge to the Content entity that is referenced via field_parent_project (relationship with Content referencing User via field_responsible)
3. Context filter via Content:Nid (relationship with Content referenced via field_parent_project)to get the Nid of parent Project
4. Was trying to add Content:Nid filter related with Content referenced via field_parent_project to filter by the Nid of parent Project.
5) "5" is a Nid of a test Parent project. The Project node with such a Nid exists on the site and some test Taks have reference to it as to parent Project.

In final, it doesn't work. I think I'm missing smth very simple with this but can't realize what... Will be very thankful for any help.

  • 1
    Hi John, welcome to Drupal Answers. This is a great start, but you are much more likely to get an answer if you include more description of the view you have created and what you are hoping to achieve with it (i.e. why are you using a view?) and/or a screenshot of the pertinent view settings. – Darvanen Feb 17 '15 at 22:24
  • @Darvanen, many thanks for your advice :) Guys, anyone? I'm already broke my brain on this issue.... – john Feb 18 '15 at 14:43

Please take a look at the views export below, this will give you user values. This will work on editing the task but not when you are initially creating the task (as the field_parent_project does not yet have a value stored against it).

$view = new view();
$view->name = 'test';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Test';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Test';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'access user profiles';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* Relationship: Entity Reference: Referencing entity */
$handler->display->display_options['relationships']['reverse_field_project_team_node']['id'] = 'reverse_field_project_team_node';
$handler->display->display_options['relationships']['reverse_field_project_team_node']['table'] = 'users';
$handler->display->display_options['relationships']['reverse_field_project_team_node']['field'] = 'reverse_field_project_team_node';
/* Relationship: Entity Reference: Referencing entity */
$handler->display->display_options['relationships']['reverse_field_parent_project_node']['id'] = 'reverse_field_parent_project_node';
$handler->display->display_options['relationships']['reverse_field_parent_project_node']['table'] = 'node';
$handler->display->display_options['relationships']['reverse_field_parent_project_node']['field'] = 'reverse_field_parent_project_node';
$handler->display->display_options['relationships']['reverse_field_parent_project_node']['relationship'] = 'reverse_field_project_team_node';
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['label'] = '';
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
/* Sort criterion: User: Created date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'users';
$handler->display->display_options['sorts']['created']['field'] = 'created';
$handler->display->display_options['sorts']['created']['order'] = 'DESC';
/* Contextual filter: Content: Nid */
$handler->display->display_options['arguments']['nid']['id'] = 'nid';
$handler->display->display_options['arguments']['nid']['table'] = 'node';
$handler->display->display_options['arguments']['nid']['field'] = 'nid';
$handler->display->display_options['arguments']['nid']['relationship'] = 'reverse_field_parent_project_node';
$handler->display->display_options['arguments']['nid']['default_action'] = 'default';
$handler->display->display_options['arguments']['nid']['default_argument_type'] = 'node';
$handler->display->display_options['arguments']['nid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['nid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['nid']['summary_options']['items_per_page'] = '25';
/* Filter criterion: User: Active */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'users';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = '1';
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Entity Reference */
$handler = $view->new_display('entityreference', 'Entity Reference', 'entityreference_1');
$handler->display->display_options['defaults']['title'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['defaults']['style_plugin'] = FALSE;
$handler->display->display_options['style_plugin'] = 'entityreference_style';
$handler->display->display_options['style_options']['search_fields'] = array(
  'name' => 'name',
$handler->display->display_options['defaults']['style_options'] = FALSE;
$handler->display->display_options['defaults']['row_plugin'] = FALSE;
$handler->display->display_options['row_plugin'] = 'entityreference_fields';
$handler->display->display_options['defaults']['row_options'] = FALSE;
  • Thanks a lot @simetau, it works perfectly. Is there any way to make it work while creating a new node? I understand field_parent_project is empty yet, but I always have the parent nid in the URL when adding a new task. – john Feb 18 '15 at 17:39

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.