I have two content types with CCK fields. One type includes a CCK field that is a node reference, the other includes a CCK field that is a user reference. Both field are Select List widgets based on Views. The view results sets are as expected when previewing them; however, I just installed the latest Views dev version (date stamped 1256344316) and when creating content the select lists are empty. I reverted to the previous dev version (date stamped 1255998945) and the select lists are populated fine.

If you need me to provide more info I would be happy to do so - I just don't know where to look.

Comments

I am also seeing this bug on Node Reference fields using the views display option with Autocomplete textfields -- the "title" field is blank/empty. The view itself is working and the title field shows up fine in views preview. This started with the Oct. 23 release (Oct. 19 release was working fine.)

Project:Views» Content Construction Kit (CCK)
Component:Code» Views Integration

Moving this to CCK primarily to get Markus' attention.

The common factor here is that I committed a patch that moves field rendering around. I didn't think it would affect other things, but it appears that this may have affected CCK. The patch I committed is #502348: How group display by mutliple fields? -- can you see if this patch has caused a problem for CCK and then we can figure out what the problem is and where it should be fixed.

Ugh, it not only affects the Select widget, but also the autocomplete widget when based on a view.

It seems the 'content_php_array_autocomplete' style is broken by this change in Views. The code is tiny and can be seen here:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/cck/include...

Playing with an autocomplete path, for example, nodereference/autocomplete/field_test_noderef/text, the result looks like this:

{ "text [nid:411]": "\x3cdiv class="reference-autocomplete"\x3e  \n  \x3cspan class="views-field-title"\x3e\n                \x3cspan class="field-content"\x3e\x3c/span\x3e\n  \x3c/span\x3e\n\x3c/div\x3e"

So it seems the value contains markup, and that breaks the nodereference widgets.

However, I'm not sure to understand the change in Views. Earl, could you please help?

Hmm. The change I made moves the rendering of fields upstream somewhat. But I'm not sure why it would affect this.

The rows should always have had markup, so I don't understand how this changed that.

hmm... looking a bit more at this, it seems the problem is not that we render markup here. Markup here is fine. The problem is that the following code generates only markup, with no data:

<?php
class content_plugin_style_php_array_ac extends views_plugin_style {
  function
render() {
   
$results = array();
   
// Group the rows according to the grouping field, if specified.
   
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);
   
$base_field = $this->view->base_field;
   
$title_field = $this->display->display_options['content_title_field'];
   
$title_field_alias = $this->view->field[$title_field]->field_alias;
   
// TODO : We don't display grouping info for now.
    // Could be useful for select widget, though.
   
foreach ($sets as $title => $records) {
      foreach (
$records as $label => $row) {
       
$results[$row->{$base_field}] = array(
         
'title' => $row->{$title_field_alias},
         
'rendered' => $this->row_plugin->render($row),
        );
      }
    }
    return
$results;
  }
}
?>

The 'rendered' elements in $result array only contain markup, without real data about the fields. So we may need to change $this->row_plugin->render($row) or the code that's behind that, but honestly, this part of CCK/Views integration is kind of obscure to me. I do not understand the flow. :(

I guess it could also be related to the following snippet from nodereference.module:

<?php
   
// TODO from merlinofchaos on IRC : arguments using summary view can defeat the style setting.
    // We might also need to check if there's an argument, and set *its* style_plugin as well.
   
$view->display_handler->set_option('style_plugin', 'content_php_array_autocomplete');
   
$view->display_handler->set_option('row_plugin', 'fields');
   
// Used in content_plugin_style_php_array::render(), to get
    // the 'field' to be used as title.
   
$view->display_handler->set_option('content_title_field', 'title');
?>

Just a quick observation: Using the latest CCK 6.x-2.x-dev (Oct-15) and the latest Views 6.x-2.x-dev (Oct-28) results in this problem. Reverting Views to the 6.x-2.6 release from June 10 fixes it.

Status:Active» Postponed (maintainer needs more info)

subscribing

subscribing

Status:Postponed (maintainer needs more info)» Needs review
StatusFileSize
new873 bytes

I've been bitten by this bug while upgrading to Views 2.7, attached patch against the latest CCK 3.x-dev seems to fix it. It's pretty much the same fix the Views Accordion module applied in #621568: Views 2.7 breaks views accordion

Title:CCK Select List based on Views empty after upgrading to latest dev versionCCK Reference fields based on views broken by recent change in views_plugin_style Views 2.7 (#502348)
Status:Needs review» Fixed

@DeFr: Thank you very much! :-)

After testing here, this seemd to fix Reference fields using Views here, so I've committed this to CCK2 and CCK3.

Just confirming that the patch works on CCK 6.x-2.5. Thank you.

A newbie quesiton, have I understood this correct: That the patch is commited means that it's commited to CVS, and will turn up in the next stable release as well as the next development release?

Marcus

Yes, the patch has been committed to CCK2 and CCK3 branches. It should be available in the next development snapshot, and of course it will be in when a new stable package is released.

PS: I'll contact yched and KarenS to evaluate if a new release of CCK worths to save time to all of us. Otherwise, all those who upgrade to Views 2.7 but keep CCK 2.5 will be affected by this issue.

(coming from #242158: nodereference dropdowns not populating with node titles when using advanced view)
Thank you, patch solves the problem. It's absolutely woth a new version. As you just stated, markus, I ran into this issue when updateing to Views 2.7, added a comment to a duplicate of this issue and I'm sure, others will follow with new duplicate issues.

Hi,

I may be having the same problem.

I have a content type that has a pull-down field where the allowed values are populate from a view. The content type also has fields that are a taxonomy tag (multi-select) and a pulldown text field with 3 possible values. If the view-pulldown come before (higher on the page) than the others, then the others are broken and have empty pulldowns and you can't select anything. If the view-pulldown comes after the other pulldowns, then they all work.

Since the site I am working on is complicated and has custom modules that do form_alters and etc, I set up a clean drupal install and tried to replicate the behavior. I have I so far not been able to; instead I have a separate problem; the views-populated pull down shows only the label, not the contents of the view output. (The view previews and works fine). It is a node reference that is using a view that has one filter (node published is yes) and one filed (Node: Title). In the pull down you see "Title: " for each possible selection, but nothing after the "Title:".

I also took the site I am working on and one by one disabled all the custom modules, but the problem still happens.

Eventually I will either have a version of my clean test site that produces the problem, and then I can post the whole db dump here, or I find some piece of the development site that I can disable to make it work, and I will focus on that. In the meantime if anyone has suggestions to narrow the search that would be appreciated.

As a final weird observation, this bug appears for user 1, and for at least some users with just "authenticated user" permissions everything works perfectly.

--Rob

Do you still experience this problem, after applying the patch? Have you installed Views 2.7 on both websites?

On the "clean" site I was using views 2.7. On the dev site I was using views 2.6, I upgraded to views 2.7, and the same behavior remains, except that now the view-based pull down also has no values in it. The 614292.patch above caused the views-based pull down to start working again, but any pull downs after it still do not work, unless you are not the admin user.

It continues to work better if you have a less privileged account, which I will try to use to narrow this down. I will hopefully post more on this tomorrow.

--Rob

So I'd suggest tu open a new issue, as the Views .27 compatibility issue is fixed for you with the patch and your problem already existed before updateing to Views 2.7.

This is already included in CCK 6.x-2.6.

I have just upgraded to both Views 2.7 & CCK 2.6, and *am* seeing this problem. It appears that CCK 2.6 did *not* fix the problem for me.

The dropdowns are empty for both admin and non-admin users.

Status:Fixed» Closed (fixed)

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

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

I think this might still be an issue for user reference field... When using autocomplete with advanced view selection, the autocomplete functionality puts the title field (I'm using a content profile relationship) as the final suggested input, instead of the username, and submitting gives this:

found no valid user with that name.

I'm using D 6.14 and views 2.8 (and CCK 2.6)

I very rarely reopen issues, so hopefully I'm not in the wrong here :)

Cheers all!

Status:Active» Closed (fixed)

@biocomp.pat: It may or it may not be related.

Please, open a separate report with as much information as possible to reproduce the issue. Thanks

In case someone else stumbles across this, I figured my issue out, but it's way to complicated a specific to do up another issue.

My advanced view selection was fairly complex, and involved a content profile relationship in order to get some of the fields I wanted displayed during user reference autocomplete. My problem (with autocomplete adding the Node:Title from the relationship instead of the User:Name) went away as soon as I added the field (Relation) Node: Title, which I didn't have before.

So now it was filling in the correct user when I'd made a choice, but it still took me a sec to figure out how to exclude the "User: Name" data from the end of each autocomplete line... like I could easily do with a node reference (see #375690-9: Nodereference autocomplete doesn't match all of view's fields)

I solved this by adding User: Name and then excluding it. I'd already had it in my view, and I think I had to remove the field then add it again to make it happen, which gave me some grief.

Anyhow, hopefully this helps someone else!

Subscribing

Status:Closed (fixed)» Active
StatusFileSize
new10.75 KB

I still have this issue using CCK 2.6 and Views 2.8. It was working fine with views 2.6.

The radios have the correct nid values, but the node title is not being displayed. The view I'm using is very simple, it only contains the node title and a couple of filters.

Meant to post here, not in #625008: Nodereference using view to select node - broken, but guess this time it was an issue with views (was using latest cck 2.6 but stable views 2.8). seems to be fixed with the latest views 2.8 dev

was wrong, still not fixed!
major problem is that $field->content in views-view-fields.tpl.php is empty (I use the raw for now to fix it). $field->content is supposed to be set in views\theme\theme.inc in template_preprocess_views_view_fields() through $field_output = $view->style_plugin->get_field($view->row_index, $id);

This call goes back to render_fields in views\plugin\views_plugin_style.inc row 31

$this->rendered_fields[$count][$id] = $this->view->field[$id]->theme($row);

Here it ends for me as I have no clue where this theming function is defined. Am not an expert on Views/CCK and have actually no clue whatsoever whats going on in there. Am not sure if this is a CCK or Views probelm. Can someone help me out on this?

PeterP - I think you meant views\plugin\views_plugin_style.inc row *231*.

It seems that this is a theme-related problem, which would explain why most people aren't seeing it. In particular, I've been having the problem with our own custom theme, but it went away when I switched to another theme (Garland).

In particular, the problem was solved for me when I deleted the template file "views-view-field.tpl.php" from my custom theme -- even though the file in my theme was identical to the file modules/views/theme/views-view-field.tpl.php!

Perhaps the views data aren't being correctly passed to the theme's template files, but are being correctly passed to the module's template files? I'm afraid I don't know much about how this happens. Can anybody else help out?

@BerkeleyJon: Thanks for the additionnal informations, it helped a lot to reproduce the issue over here :-)

Long story short: yes, copying views-view-field.tpl.php from views directory to your theme directory will trigger http://drupal.org/node/591804 , which means that Views preprocess functions don't applies as expected and you don't get the expected result. (There's also the fact that as long as it's only in Views theme folder, views-view-field.tpl.php isn't really applied, for performance, a function is used instead...)

Hopefully this D6 bug will be fixed at some point. Before that, you basically have two options: don't overide the field template or replace in your .tpl.php the $output variable with $field->advanced_render($row). (Alternatively, you should also be able to manually load Views theme.inc in a custom module hook_init). While testing though, it didn't look like this completely fixed the issue, so if at all possible simply don't override views-view-field.tpl.php

(For the record, what's setting the $output variable used in views-view-field.tpl.php is

function template_preprocess_views_view_field(&$vars) {
  $vars['output'] = $vars['field']->advanced_render($vars['row']);
}

It's probably broken in CCK only because it's using a custom style plugin which does as little rendering as possible, but theorically it will break everywhere if you override every Views theme function that are defined in its theme.inc )

subscribing

Workaround: There is one line in views that seems to cause this problem. I'm not sure if this is a CCK or Views issue but I'm posting here to show in which file in views issue originates and how to get around this issue. Using CCK 2.6 , Views 2.10 , and Chameleon theme.

See #767792: Upgrade to views-6.x.2.9 and/or 6.x.2.10 breaks existing gmap views and Content-Types based on views and comment
http://drupal.org/node/767792#comment-2831618 for more details.

I've been having this problem since Views 2.7. Now using Views 3 and CCK 2.6 -- I applied the 2 patches you're required to apply to use Views 3 + CCK.

Can't seem to get my nodereference fields (that use Views) to work anymore!! What are people doing to deal with this, exactly?

Thank you!

@me (#33)

So using the Autocomplete widget option seems to have worked, though I'm wary. Is this what people have been finding, or...?

@me, again...

So apparently I missed the memo that you have to have Node: NID as a field in a view you're using for a nodereference field? I think previously you were supposed to make your argument validate by NID or have the default argument by "node ID from URL" or something like that, but unfortunately I don't remember exactly. Let me put it this way: I added Node: NID as a field in the view I'm using for a nodereference field, and the Autocomplete and Select widgets are both working as they should for me now. I've also realized that (unlike what I said in #34) the Autocomplete widget wasn't "really working" until I did this. I say it wasn't "really working" because it was working for nodes (that have the nodereference field) in English/default language, but not for translated (Spanish) nodes. I'm not sure what the problem was -- the nodes being referenced are images that are language neutral, could be something there.

In case it matters, here's what happened when I was using the Autocomplete widget without adding the Node: NID field to my View (very similar to what others have described, but different variables, so hopefully helpful):

  • When editing an English node, I was able to reference the appropriate image nodes by typing the image node titles, waiting for Autocomplete, and selecting the option that appeared (at which point the field contents "became" "I am an image node title [nid:123]").
    • Also, if the English node I was editing already had content in the nodereference field, the Autocomplete widget/field displayed as you'd expect, with the field contents filled in normally with the appropriate content ("I am an image node title [nid:123]")
  • When editing a translated/Spanish node:
    • If it already had content in the nodereference field (which I could confirm by viewing the node normally -- the nodereference field contents displayed correctly), the Autocomplete widget/field was empty in the node-edit form. (When I was using the Select widget, the nodereference field wasn't just blank in the node-edit form, it had the default "None" option selected.) If I saved a translated/Spanish node like this, the nodereference field was cleared (confirmed by viewing the node normally).
    • When entering content into the nodereference field, I got as far as selecting an image node title that appeared under the Autocomplete widget, but at that point, the field contents "became" only "I am an image node title [nid:]" -- no NID number.
      • If I saved the translated/Spanish node with the nodereference field just like that, I got an error message like "found no valid node with that title".
      • If I copied/pasted the field contents of the corresponding English node ("I am an image node title [nid:123]") and saved it, I got an error message "[nodereference_field_name]: this post can't be referenced".

As I mentioned previously (#33), I'm running Views 3 and CCK 2.6, with the two views3+CCK patches, and I've experienced variations of this bug since Views 2.7 (though I skipped from 2.8 to 3). (Earlier the bug didn't seem to delete field contents, the nodereference field/Select widget was just blank -- not "None".) I have not copied "views-view-field(s).tpl.php" (or any Views templates) into my custom theme directory (nor have I customized any Views templates in the module directory). Please let me know if there are any other details I can provide to help work on this problem. Thank you!

I've met the problem. (Views 6.x-2.10, CCK 6.x-2.6).
I had a complicated view with 2 relationships (both user and node reference).
Names of fields generated by views were strange: instead of title and nid fields, i got title for node, but nid for related field. I looked at views sql:

SELECT node.nid AS nid, node_node_data_field_modules.title AS node_node_data_field_modules_title, node_node_data_field_modules.nid AS node_node_data_field_modules_nid, node.title AS node_title

content_plugin_style_php_array_ac.php can't handle such things, so i got a listbox with only one value.

I have encountered this problem with nodereference.

The view I have created was giving the correct output but when I go to add content, the drop down list shows "Title:" and then 2 of the four required results on a horizontal line.

Tried the things that have been mentioned by "alinsonjo2786" above but still no luck.

Hope there is a solution???

In case it is useful to anyone else I also had this problem - my node reference field was working fine but since upgrading views no longer had any items to select, and I tried the suggestion above of adding node: nid as a field to the view, and it then worked as before. You can also set the nid not to display and it still works.

I was having the exact same issue with a node reference and just a simple view - blank values. I upgraded to CCK 2.7 and Views 2.11 and the issue went away. I verified that autocomplete, radio and select lists all work.

Now, if someone could tell me how to expose a views filter in this scenario, my problems would really be solved!

Also had the same problem - node reference not populating select list.
It got solved by adding node: nid as a field to the view.

Working with CCK 6.x-2.7 and Views 6.x-3.0-alpha3.

A follow-up to my post above:

If the 'Number of Values' of the field is set to have any no. more than 1, it does not remain a Select list drop-down, instead the complete list is expanded on the form.

same problem

subscribe
not sure yet if it's related to me as I have one node reference field that is ok, and another could be displayed if I only add there node:nid or other CCK fields.

Version:6.x-2.6» 6.x-2.9

Hi there,

Well, after a lot of reading and searching for a solution to my problem and a lot of tests, I should admit that I have no idea how to fix my problem, and that I have this problem with Drupal 6.20, CCK 2.9 & Views 2.12, so all the latest releases for D6 :

I created a NodeReference field with multiple values on a User Profile (with Content Profile) called 'Structures', a 'Structure' being a normal content type with CCK fields. From that profile, I wanted to reference items that would enable me to short list the access of the current logged in user to these items and their child nodes (a sort of custom business ACL). Then I created a 'Product' content type with a nodereference field (Selection widget) referencing a 'Structure' (for the structure manages the product, and a user has responsability for a shortlist of Product).

From there I created some other content types (lets call them X) all referencing a 'Product', all having a node reference field (selection widget) to let the user choose in a list of available Products.
My point was to use Views to restrict the products available in the select list to the ones managed by the Structures referenced in the current User Profile (complicated but necessary to explain my problem !) : with the help of the Reverse Node Reference module, I got the correct preview for my shortlist, except that in the selection widget only one result appear (I know of that problem, and read about solutions in other posts - this is not my main point here).

To get over that, I created a small module called Views Custom Prerender overriding views_pre_render(&$view) just to replace the nid row result (which was, whatever the query, the nid of the user) with the X nid (X being a content type I mentionned earlier). The outcome being that my selection list is correctly populated with the correct names and stuff, BUT :

when I try to create a X, selecting a Product in the user-customed shortlist, I have the following error message :

"This post can't be referenced".

So my problem is not about correct display of the selection list, but about validation and content population after form submission.
Following all the discussions in that list, I also looked in the nodereference.module file, line 841 :

$view->display_handler->set_option('style_plugin', 'content_php_array_autocomplete');

which still looks to be the problem to me, given that the following line (line 897) :
$result = $view->execute_display($display, $view_args);

returns no result, which is why the error message is triggered.

Please somebody, help me, I did all my best those last days but I ran out of ideas or solutions....
Big thanks,

By the way, here is the code of my Views Custom Prerender module :

<?php
function views_custom_prerender_views_pre_render(&$view)
{
  if ($view->name == 'from_profile_produits')
  {
    foreach ($view->result as $row)
    {
        $row->nid = $row->node_node_data_field_structure_nid;
    }
  }
}

$row->node_node_data_field_structure_nid being the nid of the X content type being rendered by the view to populate the selection list. Thank you guys.

OK, I mostly found my problem, but not how to solve it.
The problem comes that by creating a "Views Custom Prerender" override module, I messed up the query executed at validation time, during the X content type creation. Of course, the whole was a bad idea, but what to do when you have nothing else ?
Because overriding the $row->nid in the $view->result corrupted the 'INNER JOIN' clause in the auto-generated view query.

I fixed it the very very hard way, meaning adding that very ugly code to the cck/includes/views/handlers/content_plugin_display_simple.inc, line 37 :

    elseif ($options['ids']) {
      $alias = $this->view->query->ensure_table($options['table']);
  /*** my editing begins ***/
  $alias_old = $alias;
  $field_old = $options[field_id];
  if ($this->view->name == 'from_profile_produits') {
$alias = 'node_node_data_field_structure';
  }
  /*** my editing ends ***/
      $this->view->query->add_where(NULL, "$alias.$options[field_id] IN (" . db_placeholders($options['ids']) . ')', $options['ids']);
    }

with node_node_data_field_structure being the temporary field containing the correct nid of the object I was looking for.

I know everything of that is very very poor, but still, let me share it to you, still hoping for a miraculous solution to avoid it...

#40 adding the Node ID to the fields and selecting exclude form display made my multiple selectbox nodereference field show the list values in the view. Thanks!

Status:Active» Needs review
StatusFileSize
new2.93 KB
new2.93 KB

I 100% agree with #35 - my view+select list was not working and I had no clue as to why until I found this issue. I did not realize nor did I find documentation that specified that Node:NID must be in the view.

I created a documentation patch for both CCK trees that indicate that for select widgets you need to include Node:NID in the view. That's a few hours of my life I won't get back so hopefully this will help someone else if we can get it in.

On another note, I also found this helpful: #998494: Node Reference field always displaying 10 results when using the Advanced View option. [views-6.x-3.x], which is a different problem but was related to seeing the correct output in my view.

Version:6.x-2.9» 6.x-3.0-alpha3
StatusFileSize
new31.95 KB

I still have issue:
- a node reference field correctly displays values for selected nodes
- the same field as exposed filter is not populated
- I tried to add a node:nid hidden field, but it did not help

Attached an export of the views
The problematic field is called "Publication" - the field is OK, the filter is not.

Any help appreciated

I also have a similar issue.
#1166234: Field values aren't displayed when using Views to filter node reference select list (/w Fix)
My comments are there.
For the node title, I can see its label, but not its data !

Hi guys,

I'm also getting this, using CCK 2.9 and Views 3.0. The process?

1) Set up a node reference
2) Choose a view to select from
3) Edit the node in question to pull the special list in

The view was built with absolutely nothing but a 'Node: Title' field. There's no trickery going on, it's a view that will spit out the title of every node created on the site. The node reference however, pulls back nothing.

Really not sure on how to approach a possible fix, because I don't think this piece of functionality works properly.

EDIT: Grammar

Need a solution on this guys. Node Reference is broken at the moment.

Bump.

StatusFileSize
new9.27 KB

What version of CCK and Views are you using. My Node references that are using views are all not working correctly.
the auto complete ones fits all of the correct nodes as tiny, tiny lines into the small drop box. When I change it to a select list. The values are correct but the displayed values are blank. See below:

<option value="736"> 
</option>

Views 6.x-2.16 CCK 6.x-2.9

Narrowing it down a bit, I have found that either the data isn't being pass, or it is not being rendered correctly in content_plugin_style_php_array_ac.inc ... line 24 - 27 :

$results[$row->{$base_field}] = array(
          'title' => $row->{$title_field_alias},
          'rendered' => $this->row_plugin->render($row),
        );

Specifically the 'rendered' field. 'title' is going through it seems, but the rendered row is coming back as an empty string.
Any thoughts as to why? This is the same scheme that is used in the jump menu for views. Labels are coming through, If I add labels to each field, the labels show up inline, but the actual field data does not.
Even if the view is executed earlier in the nodereference.module script, say line 859, 'renedered still only provides the labels for each of the fields and not the field values. Am I missing something on how to set up the view. I have three fields, and they are NID, Title, and another field.

I switched to using a table display, and I am re-using the view in multiple node references on the same page, and the first field reference has a problem, the others on the page render properly. Even if I change the order of the fields on the edit/add page the first one will not display correctly, the Rows do not render, but the second and so forth the rows will render. Is there a method to pre-render the view, so that it will work the first time through?
Has anyone else found a work around, or solved this? I am really stuck.

This is not just for the select list view, all of the node reference fields work AFTER the first one doesn't function, The widget type does not matter.