I downloaded the views module and I am doing pretty well in using it. I did notice a problem today when I created a view for a block. When I choose the field (node title) then check of the box "Exclude from display" I no results, and this error:

warning: Invalid argument supplied for foreach() in D:\....\modules\views\theme\views-view-fields.tpl.php on line 22.

If I uncheck this box, the error goes away and the view works properly.

Thanks for looking into this.

Comments

dave4050’s picture

I found the problem. If there is any text in the "Label" field and you check the "exclude from display box", you get that error. The label field must be left blank. Maybe this could be error trapped and a clearer message given if this happens? Thanks again.

dave4050’s picture

I misunderstood the purpose of the label field. This happens if you have one field listed, and you select exclude.

ff1’s picture

This error occurs in the 'Live preview' area of the page. It is trying to generate a preview of a view which has no data.

When this occurs, it should revert back to the error 'Display ... uses fields but there are none defined for it.' which is present when no fields have been selected.

jrabeemer’s picture

Version: 6.x-2.0-rc1 » 6.x-2.x-dev
Component: block displays » page displays
Priority: Normal » Critical

I ran into this bug.

Add a page view, change to Style: List, Row style: Fields, Add Node: Title, Click node: title, blank the Label field then check on exclude from display. Boom!

You get the warning in the preview and output view page:

warning: Invalid argument supplied for foreach() in /Users/blah/Sites/carmen/cgv3/web/trunk/www/sites/all/modules/views/theme/views-view-fields.tpl.php on line 22.

The bug rears its head if you add node: title first. If I add Node: Title last, then reorder back to top position, toggle the exclude display checkbox, the warning doesn't appear again.

Any thoughts merlin?

jrabeemer’s picture

The view:

$view = new view;
$view->name = 'news';
$view->description = 'News items go here';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'link_to_node' => 1,
    'exclude' => 1,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'created' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'news' => 'news',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('title', 'News');
$handler->override_option('empty', 'No news available.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', 'mini');
$handler->override_option('style_plugin', 'list');
$handler->override_option('row_options', array(
  'inline' => array(),
  'separator' => '',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'news');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
jrabeemer’s picture

Error also happens if I check on all fields Exclude from display, nothing showing..

$view = new view;
$view->name = 'news';
$view->description = 'News items go here';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => '',
    'link_to_node' => 1,
    'exclude' => 1,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'teaser' => array(
    'label' => '',
    'exclude' => 1,
    'id' => 'teaser',
    'table' => 'node_revisions',
    'field' => 'teaser',
    'relationship' => 'none',
  ),
  'created' => array(
    'label' => '',
    'date_format' => 'custom',
    'custom_date_format' => 'F j, Y',
    'exclude' => 1,
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'created' => array(
    'order' => 'DESC',
    'granularity' => 'second',
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'news' => 'news',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'status' => array(
    'operator' => '=',
    'value' => 1,
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'status',
    'table' => 'node',
    'field' => 'status',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler->override_option('title', 'News');
$handler->override_option('empty', 'No news available.');
$handler->override_option('empty_format', '1');
$handler->override_option('use_pager', 'mini');
$handler->override_option('style_plugin', 'list');
$handler->override_option('row_options', array(
  'inline' => array(),
  'separator' => '',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'news');
$handler->override_option('menu', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));
$handler->override_option('tab_options', array(
  'type' => 'none',
  'title' => '',
  'weight' => 0,
));

merlinofchaos’s picture

This strikes me as the equivalent of hitting oneself in the head and going "OW IT HURTS FIX IT".

Seriously, what compels people to exclude all their fields from display anyway? If you add a bunch of fields, then exclude them all, were you planning on something magical happening?

jrabeemer’s picture

Well that may be true but it still occurs if you exclude ONE field. In this example, the first field, node: title.

It makes sense to exclude all if you are overriding the theme function for advanced theming I think. I'm not exactly sure since the documentation isn't so good.

merlinofchaos’s picture

I'm not exactly sure since the documentation isn't so good.

Great, you're volunteering to write a couple pages of documentation, then?

merlinofchaos’s picture

I just checked, and I can't duplicate this issue by excluding just one field, with a label filled in.

ff1’s picture

I have managed to duplicate this issue using views 6.x-2.0-rc1. I haven't tried with the latest -dev version. Here are the steps to repeat it:

1. Create a new view of type Node, using any title and description.
2. Without changing any other settings on the 'Edit view' page, click on the + button to add a new field.
3. Select the 'Node: Title' field and click Add.
4. Leave all other settings as default except select 'Exclude from display' before clicking Update.
5. The error should then appear in the Live preview pane.

I don't know of a use case for this, but the above definately repeats it for me. My test site is still using Drupal 6.3 and CCK 6.x-2.0-rc4. I don't know if that makes a difference.

Note: The error was displayed no matter which field I selected in step 3. The error continues to be displayed if I add more fields with the 'Exclude from display' option selected.

merlinofchaos’s picture

Try it with -dev as quite a bit has been fixed since then, and I've already been unable to duplicate this with the -dev version.

merlinofchaos’s picture

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

Status: Postponed (maintainer needs more info) » Fixed

I can now confirm that this issue has been fixed in 6.x-2.0-rc3. Running through the procedure in #11 produces the user friendly error message "Display Defaults uses fields but there are none defined for it or all are excluded.".

Thanks merlinofchaos!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

excaliburst’s picture

Version: 6.x-2.x-dev » 6.x-2.3
Status: Closed (fixed) » Active

Hi guys,

I am so sorry - but it seems this problem has not been fixed.

I get this error
Display "Defaults" uses fields but there are none defined for it or all are excluded.

when I try to save any changes to either a new view or try to save a modification to any of the existing templates that come with Views.

Any ideas? I am building a production site and this is a critical showstopper.

I am running Drupal 6.9 with Views 6.x-2.3 module enabled

I read here http://www.tmtdigital.com/node/422

That the fault could be my permissions for the following could be the culprit
load all node data
load own node data

But I seem to not be able to find these permission under User Permissions. Hmmmm Why not?

Thanks guys

Morten E.

merlinofchaos’s picture

Status: Active » Closed (fixed)

This issue does not appear to be related. Please open a new issue. (Also, when you do, explain why you feel the error message you're getting is wrong. You don't actually say, for example, that you added fields).