1

I have a content type that has an entity reference (user field) field_mr_mission_supervisor. The user accounts have a date field field_user_end_date. I'm trying to Filter the field_mr_mission_supervisor field to exclude users that have a value in the end date field that is prior to NOW (users that have left). I discovered that the view has an effect when the widget type is Autocomplete (tags style) but not when it is just autocomplete. For consistencies sake I'd really like to use plain autocomplete, so users have an add button for adding multiple users instead of having to deal with comma separation which really only works for things like tags.

I tried the patch in this issue, but it seems to not have any effect. I also tried enabling the synonyms module, since the maintainer of that project commented that he had an autocomplete field that worked with the field, but I got no add buttons, even when I switched my widget to the synonyms widget.

My question is related to this one, but that one did not get an actual answer about how to do the limiting in code, and that answer seems to imply that a normal autocomplete widget should work with the views filter. Since my filter is pretty simple, is there a way I could replicate it in a module, to filter out users with an end date that is filled in and in the past?

My end goal is to have an entity reference (user) field with an autocomplete widget that filters out users with an end date field containing a date in the past, so any answer that accomplishes this will work just fine for me.

Here is a screenshot of the view: enter image description here

And here is the export:

$view = new view();
$view->name = 'active_staff_list';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Active Staff List';
$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['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['style_plugin'] = 'default';
$handler->display->display_options['row_plugin'] = 'fields';
/* 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']['exclude'] = TRUE;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
/* Field: Realname: Real name */
$handler->display->display_options['fields']['realname']['id'] = 'realname';
$handler->display->display_options['fields']['realname']['table'] = 'realname';
$handler->display->display_options['fields']['realname']['field'] = 'realname';
$handler->display->display_options['fields']['realname']['label'] = '';
$handler->display->display_options['fields']['realname']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['realname']['link_to_user'] = FALSE;
/* Field: User: Family Name(日本語) */
$handler->display->display_options['fields']['field_user_ja_family_name']['id'] = 'field_user_ja_family_name';
$handler->display->display_options['fields']['field_user_ja_family_name']['table'] = 'field_data_field_user_ja_family_name';
$handler->display->display_options['fields']['field_user_ja_family_name']['field'] = 'field_user_ja_family_name';
$handler->display->display_options['fields']['field_user_ja_family_name']['label'] = '';
$handler->display->display_options['fields']['field_user_ja_family_name']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_user_ja_family_name']['element_label_colon'] = FALSE;
/* Field: User: First Name(日本語) */
$handler->display->display_options['fields']['field_user_ja_first_name']['id'] = 'field_user_ja_first_name';
$handler->display->display_options['fields']['field_user_ja_first_name']['table'] = 'field_data_field_user_ja_first_name';
$handler->display->display_options['fields']['field_user_ja_first_name']['field'] = 'field_user_ja_first_name';
$handler->display->display_options['fields']['field_user_ja_first_name']['label'] = '';
$handler->display->display_options['fields']['field_user_ja_first_name']['exclude'] = TRUE;
$handler->display->display_options['fields']['field_user_ja_first_name']['element_label_colon'] = FALSE;
/* Sort criterion: User: Family Name (field_user_family_name) */
$handler->display->display_options['sorts']['field_user_family_name_value']['id'] = 'field_user_family_name_value';
$handler->display->display_options['sorts']['field_user_family_name_value']['table'] = 'field_data_field_user_family_name';
$handler->display->display_options['sorts']['field_user_family_name_value']['field'] = 'field_user_family_name_value';
$handler->display->display_options['filter_groups']['groups'] = array(
  1 => 'AND',
  2 => 'OR',
);
/* 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;
/* Filter criterion: User: End Date (field_user_end_date) */
$handler->display->display_options['filters']['field_user_end_date_value']['id'] = 'field_user_end_date_value';
$handler->display->display_options['filters']['field_user_end_date_value']['table'] = 'field_data_field_user_end_date';
$handler->display->display_options['filters']['field_user_end_date_value']['field'] = 'field_user_end_date_value';
$handler->display->display_options['filters']['field_user_end_date_value']['operator'] = '>';
$handler->display->display_options['filters']['field_user_end_date_value']['group'] = 2;
$handler->display->display_options['filters']['field_user_end_date_value']['default_date'] = 'now';
/* Filter criterion: User: End Date (field_user_end_date) */
$handler->display->display_options['filters']['field_user_end_date_value_1']['id'] = 'field_user_end_date_value_1';
$handler->display->display_options['filters']['field_user_end_date_value_1']['table'] = 'field_data_field_user_end_date';
$handler->display->display_options['filters']['field_user_end_date_value_1']['field'] = 'field_user_end_date_value';
$handler->display->display_options['filters']['field_user_end_date_value_1']['operator'] = 'empty';
$handler->display->display_options['filters']['field_user_end_date_value_1']['group'] = 2;

/* 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'] = 'none';
$handler->display->display_options['pager']['options']['offset'] = '0';
$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(
  'realname' => 'realname',
  'field_user_ja_family_name' => 'field_user_ja_family_name',
  'field_user_ja_first_name' => 'field_user_ja_first_name',
  'name' => 0,
);
$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;
$translatables['active_staff_list'] = array(
  t('Master'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Items per page'),
  t('- All -'),
  t('Offset'),
  t('« first'),
  t('‹ previous'),
  t('next ›'),
  t('last »'),
  t('Entity Reference'),
);
  • Mind posting a screen shot of your view's config? – No Sssweat Nov 30 '17 at 4:58
  • Sure thing, I added a screenshot and the view export – UltraBob Nov 30 '17 at 5:36
  • Does the view preview show the results that you expect? Doesn't list the users that shouldn't be showing up on the auto complete? – No Sssweat Nov 30 '17 at 9:57
  • Yeah the preview is correct. The issue is that the autocomplete widget won’t use the view filter, so Inwas wondering if there was a quick way to do that filter in a module instead. – UltraBob Nov 30 '17 at 10:39
  • 1
    Looks like you'll have to do it programmatically then. Here is an example – No Sssweat Dec 6 '17 at 1:51

Your Answer

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

Browse other questions tagged or ask your own question.