Selecting <None> displays the first view of the site (and it's not even in the allowed list ;)
miiimooo - July 3, 2009 - 14:49
| Project: | Viewfield |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Jump to:
Description
I have these field settings:
- Required: No
- Allowed views: selected one
- nothing else ticked
When creating content I see am option in the viewfield. Selecting it and then clicking on preview lists the first view (of the site) instead of none.
I found this: viewfield.module
<?php
function _viewfield_potential_references($field_settings = TRUE, $field = array(), $delta = 0) {
...
if (!$field_settings && (!$field['required'] || ($field['multiple'] && $delta > 0))) {
// drupal_set_message("<pre>" . print_r($options, TRUE) . "</pre>");
// array_unshift($options, '<'. t('none') .'>');
$options[NULL] = '<'. t('none') .'>';
?>Otherwise it gives a value of '0' later on.
<?php
function viewfield_field($op, &$node, $field, &$items, $teaser, $page) {
...
case 'sanitize':
foreach ($items as $delta => $item) {
if (empty($item['vname'])) {
$items[$delta] = array("vname"=>NULL,"vargs"=>NULL);
continue;
}
$item = empty($item['vname']) || $field['widget']['force_default'] ? $field['super_default_widget'] :
?>This fixes the problem for me. But I think it needs a better fix in case people use the force default stuff.
Great module BTW!!!

#1
Actually I think I found a simple solution for this - although it's more like a workaround but might help someone else.
<?phpfunction _viewfield_potential_references($field_settings = TRUE, $field = array(), $delta = 0) {
..
if (/*!$field_settings && */(!$field['required'] || ($field['multiple'] && $delta > 0))) {
array_unshift($options, '<'. t('none') .'>');
}
?>
This allows setting the default view to in the field settings and leaves the default on when editing content.
#2
If you don't choose the option to 'force default' the field still saves whatever view is selected as a 'global default value'. If you haven't selected a view, it ends up saving the first view in the list as the 'global default value'. Then on pages where you don't select any view there is some borked logic that displays the global default view even if you have not chosen 'force default'.
This fix doesn't take care of the borked logic, but at least allows the default to be no view instead of whatever view happens to be the first one in the list.
This is a fairly critical problem that actually makes the field unusable if you don't want a default view.
#3
To replicate the problem:
1) Add a viewfield to a content type.
2) Leave 'force default' unchecked and select no view as a default and make it not required.
3) Create a new page for this content type and leave the viewfield empty to display no view on that page.
4) You will see the first view in the viewfield list instead of no view.
#4
Thanks for this snippet miiimooo. This problem was kicking my ass, and would have taken me ages longer to figure out without that.
#5
Marked #484850: Not choosing any view not possible as duplicate of this issue.
#6
Hi there,
can someone please post the full corrected viewfield.module code/file?
I am not quite sure where to put the additional 3 lines within that block, and I'm also having the issue that always *something* is displayed....
Thanks a lot!
Robert
#7
Issue is reproducible with today's -dev.