When I create a block that has an argument UID of currently logged in user , I get this error in reports below:

Location http://localhost/admin/structure/views/ajax/config-item/welcome_block/bl...
Referrer http://localhost/admin/structure/views/view/welcome_block

Notice: Undefined index: current_user in views_handler_argument->options_validate() (line 398 of /var/www/vhosts/localhost/httpdocs/sites/all/modules/views/handlers/views_handler_argument.inc).

How can this error be fixed?

Comments

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

Dear BeaPower, you are really active in the issue queue and posted already quite some questions in the views issue queue.
Everytime you get the question from us: please provide an export of the view, it saves seconds, but that's actually the threshold whether people work on bugs or not.

Additional please provide a view which can be reproduced without using fancy fieldapi fields.

BeaPower’s picture

hi, yes I am very active here I see and recognizable! :) But here is an export of my view, thanks.

$view = new view;
$view->name = 'welcome_beauty';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'users';
$view->human_name = 'Welcome Beauty';
$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'] = 'Welcome Beauty';
$handler->display->display_options['css_class'] = 'welcomebeauty';
$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['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '1';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
'picture' => 'picture',
'name' => 'name',
'nothing' => 'name',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
'picture' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '',
'empty_column' => 0,
),
'name' => array(
'sortable' => 0,
'default_sort_order' => 'asc',
'align' => '',
'separator' => '
',
'empty_column' => 0,
),
'nothing' => array(
'align' => '',
'separator' => '',
'empty_column' => 0,
),
);
$handler->display->display_options['style_options']['override'] = 1;
$handler->display->display_options['style_options']['sticky'] = 0;
$handler->display->display_options['style_options']['empty_table'] = 0;
/* Field: User: Picture */
$handler->display->display_options['fields']['picture']['id'] = 'picture';
$handler->display->display_options['fields']['picture']['table'] = 'users';
$handler->display->display_options['fields']['picture']['field'] = 'picture';
$handler->display->display_options['fields']['picture']['label'] = '';
$handler->display->display_options['fields']['picture']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['picture']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['picture']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['picture']['alter']['external'] = 0;
$handler->display->display_options['fields']['picture']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['picture']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['picture']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['picture']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['picture']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['picture']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['picture']['alter']['trim'] = 0;
$handler->display->display_options['fields']['picture']['alter']['html'] = 0;
$handler->display->display_options['fields']['picture']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['picture']['element_default_classes'] = 1;
$handler->display->display_options['fields']['picture']['hide_empty'] = 0;
$handler->display->display_options['fields']['picture']['empty_zero'] = 0;
$handler->display->display_options['fields']['picture']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['picture']['imagecache_preset'] = 'avatars_65';
/* 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']['alter_text'] = 1;
$handler->display->display_options['fields']['name']['alter']['text'] = 'Welcome back, [name]!';
$handler->display->display_options['fields']['name']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['name']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['name']['alter']['external'] = 0;
$handler->display->display_options['fields']['name']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['name']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['name']['alter']['word_boundary'] = 0;
$handler->display->display_options['fields']['name']['alter']['ellipsis'] = 0;
$handler->display->display_options['fields']['name']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['name']['alter']['trim'] = 0;
$handler->display->display_options['fields']['name']['alter']['html'] = 0;
$handler->display->display_options['fields']['name']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['name']['element_default_classes'] = 1;
$handler->display->display_options['fields']['name']['hide_empty'] = 0;
$handler->display->display_options['fields']['name']['empty_zero'] = 0;
$handler->display->display_options['fields']['name']['hide_alter_empty'] = 0;
$handler->display->display_options['fields']['name']['link_to_user'] = 1;
$handler->display->display_options['fields']['name']['overwrite_anonymous'] = 0;
$handler->display->display_options['fields']['name']['format_username'] = 1;
/* Field: Global: Custom text */
$handler->display->display_options['fields']['nothing']['id'] = 'nothing';
$handler->display->display_options['fields']['nothing']['table'] = 'views';
$handler->display->display_options['fields']['nothing']['field'] = 'nothing';
$handler->display->display_options['fields']['nothing']['label'] = '';
$handler->display->display_options['fields']['nothing']['alter']['text'] = 'Logout';
$handler->display->display_options['fields']['nothing']['alter']['make_link'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['path'] = 'user/logout';
$handler->display->display_options['fields']['nothing']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['external'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['nothing']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['trim'] = 0;
$handler->display->display_options['fields']['nothing']['alter']['html'] = 0;
$handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['nothing']['element_default_classes'] = 1;
$handler->display->display_options['fields']['nothing']['hide_empty'] = 0;
$handler->display->display_options['fields']['nothing']['empty_zero'] = 0;
$handler->display->display_options['fields']['nothing']['hide_alter_empty'] = 0;
/* 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';
/* 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'] = 0;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');

dawehner’s picture

I'm a bit confused because this view doesn't have a contextual filter/argument.

BeaPower’s picture

I removed it to avoid a WSOD, but you can add the arguement user - uid - logged in

yurg’s picture

StatusFileSize
new22.76 KB

Hello,

Guess I'm same here with Views 7.x-3.x-dev (installed due to EntityAPI maintainers suggestion from http://drupal.org/node/1334168#comment-5245246 ) and Notice: Undefined index: node in views_handler_argument->options_validate() (line 398 of /home/admin/public_html/beta/sites/all/modules/views/handlers/views_handler_argument.inc).

I tried to create view which utilize node_reference Relationships and Content:NID Contextual filters. It's not first time I uses this Views features together and it always went fine, so, after checking various combinations of Relationships and Contextual Filters I was lucky enough to check Watchdog, where Notice listed above was found. Please found my View export attached (it's quite big to be listed online).

Thank you!

yurg’s picture

Status: Postponed (maintainer needs more info) » Active
joelstein’s picture

I too am getting a "Notice: Undefined index: node in views_handler_argument->options_validate() (line 398 of sites/all/modules/views/handlers/views_handler_argument.inc)." error with a view that has node reference relationships and a content:nid contextual filter.

Glenmoore’s picture

Version: 7.x-3.x-dev » 7.x-3.3
StatusFileSize
new8.53 KB

D 7.10
Looks like I have the same problem:

The following error message appears when I "Apply" but goes away when I Save the view.

"Notice: Undefined index: current_user in views_handler_argument->options_validate() (line 413 of sites/all/modules/views/handlers/views_handler_argument.inc)."

The block "does not have a source for contextual filters" so I have a Default Value set to "User ID from logged in user" and "Only allow numeric UIDs " for validation. I have an integer CCK field in the content type containing an integer representing the uid (I am using this field as the Context Filter). It works perfectly in the Preview when I feed it the uid argument but when I put it into a panel I get whatever I ask for in the "if does not validate" box.
Just upgraded to 7.x-3.3 no change.

Edit: Please ignore the last part of this just my own stupidity, I'm afraid. I had been over-riding the Context within the panel. Error message still appears but apparently no side effects.

Glenmoore’s picture

Version: 7.x-3.3 » 7.x-3.x-dev

Ok, as painful as this is to admit, it seems I am even more of an idiot than I initially thought. Now my error message has disappeared. No idea why but I am re-setting version number. Apologies again.

tim.plunkett’s picture

Just a note that the current line number for this is now handlers/views_handler_argument.inc, line 422.

As of http://drupalcode.org/project/views.git/commit/0b00ced

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett

If a plugin has no options_form, the $form_state['values']['options'] has no empty array for it, causing the notice.

There are two to three places to fix this. One, put isset() checks in, two, loop through the options and set missing ones to array() at the beginning of views_handler_argument::options_validate(), and the ideal fix, which I haven't located, in which the options have an empty array in the form_state despite having no options.

Compare views_plugin_argument_default_user and views_plugin_argument_default_current_user, the current_user plugin will never have any options.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new737 bytes
new837 bytes

Okay, so I think my mythical third solution is prevented by the Form API. Maybe I'm wrong.

Here are two other approaches.

Argument default plugins without options: node, current_user

Also, none of the plugins even have a options_validate() method.

dawehner’s picture

My personal vote would be the "other" patch, because it still calls options_validate even there are no options. You never know what crazy things people do in their custom code, but more important it's more how people expect it to work.

tim.plunkett’s picture

Status: Needs review » Needs work

Okay I think I found a better fix. Back with a patch in a bit.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.21 KB
new4.81 KB

Okay, here we go! And a test!

Status: Needs review » Needs work

The last submitted patch, views-1272524-15-tests-only.patch, failed testing.

tim.plunkett’s picture

Assigned: Unassigned » dawehner
Status: Needs work » Needs review

Awesome.

dawehner’s picture

Status: Needs review » Fixed

Cool, this fix is perfect, as it's done on the validators similar. Committed to 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.