Hello, i used Nodereference 6.x-2.2 and this moduel works only with 1item in the nodereference field. Is it true? Maybe you can reproduce this. So wrote a little patch. Please comment.
function theme_nodereference_views_formatter_views($element) {
// We get here even if the field is empty, so check that the 0 value is not a proper nid
// and return nothing so the label is not shown.
$field = $element['#field_name'];
foreach($element['#node']->$field as $k => $v) {
if($v['nid'] != "") {
$nids[] = $v['nid'];
}
}
if($nids) {
$arg_nids = implode(',', $nids);
} else {
$arg_nids = array();
}
// Don't use views_embed_view so we can return an error if the view can't be found.
$view_name = $element['#field_name'];
$args = array($arg_nids);
$view = views_get_view($view_name);
if (!$view) {
return "Error: view $view_name not found.";
}
return $view->preview('default', $args);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | ppi_node_2662_OK_embedded_titles_externals.png | 112.39 KB | webel |
| #6 | ppi_node_2662_BUG_nodereferenceviews_multiple_embedded_missing.png | 96.38 KB | webel |
Comments
Comment #1
joachim commentedWeird. I'm on CCK 6.x-2.2 too and it works fine.
Could you do a debug output with dsm($element) and paste it here please? (You'll need devel.module for that).
Comment #2
webflo commentedavoid invalid arguments with is_numeric
Comment #3
joachim commentedI've fixed this, but I think this is also a bug in CCK: http://drupal.org/node/422036
Can you try the dev release once it appears and let me know if it's fixed your problem?
Comment #4
webflo commentedyour patch works fine. no problems with empty items from nodereference field. thanks.
Comment #6
webel commented2010-03-26: The entire matter (below) was a wild goose chase. The entire problem was that in the view (for some unknown reason) the setting
Allow multiple terms per argumentfor the view argumentNode: Nidwas not checked TRUE. Please read however my remarks about what I feel about how unnecessarily hard it is to investigate certain problems in Drupal sometimes, because of the way it is coded. I have apologised to maintainer joachim for wasting his time. Dr Darren Kelly (Webel IT Australia)Reopening w.r.t. following module versions:
Node reference views 6.x-1.2
Views 6.x-2.x-dev
Content 6.x-2.x-dev
Please see 2 attached images, the 1st shows 3 referenced nodes as title links for a field 'field_defining_document'
(happens to be displayed within a Fieldgroup), the 2nd shows the result with NodeReferenceViews,
and I've tested the 2nd and 3rd referenced nodes by arg %nid directly in the view 'field_defining_document' already
in the Views UI, it runs fine, NodeReferenceViews is clearly not iterating over all referenced nodes, just the first.
Grateful for any feedback, Webel
Comment #7
webel commentedbumping.
Comment #8
joachim commentedCould you debug to check the noderef field formatter is getting all the nids, and likewise the view argument handler is getting them?
Comment #9
webel commentedHi, am resuming investigation of this.
Copying and pasting the Krumo output of dsm($element) at entry to theme_nodereference_views_formatter_views($element):
As you can see, in this case there are three referenced nids: 2664, 2667, 2669.
I continued debugging stage by stage:
This gave correctly the 3 nids within an array:
And then:
This yields not an array of nids, rather a string with comma separated nid strings:
The above is literal, i.e. it is one string with commas between numeric characters.
I can't imagine why on earth anybody would ever want to handle args like that
(and I looked at http://drupal.org/node/422036). Continuing through:
Gives:
Which eventually gets passed to:
Comment #10
joachim commented> I can't imagine why on earth anybody would ever want to handle args like that
Because that is the only way to do it! The Views node ID argument has to have all the values in a single string it can recognize.
Everything is working as it should so far.
Are you on the latest version of Views?
What does the node ID argument receive?
Comment #11
webel commentedI googled around '$view->preview' without success to find out why one might pass the nid args as '2664,2667,2669', and am none the wiser. I tried naively overriding the implode trick with $arg_nids, thus:
It gives as expected an array with 4 elements, where the first three are the referenced nids, and the last is the nid of the page in which the nodereferenceview should appear.
The served page still only shows a view result for the first nid, in this case 2664.
Comment #12
webel commented@joachim
Thanks for the world's fastest response, and I now understand why you are using the implode trick (although I do not understand why preview needs to be fed that way).
Although I know plenty of PHP, I am a UML+Java person, and I find the way arguments and functions as names hidden within arrays are thrown around in Drupal infuriating and mostly unnecessary, and sometime just plain sloppy. It drives me crazy.
Am looking into direct args fed to Views UI, will report back in minutes ...
Comment #13
webel commented@joachim If I am to test directly (again) in the Views UI admin page for the view
field_defining_document(which can be multiple), what would you expect me to feed into the dialog ? The interface requests:I know of course how Views and View UI work, I use them every day, however I do not know whether this relates directly to
$view->previewComment #14
webel commentedWhere can I find out what
$view->preview('default',$args)expects ? Is it documented as part of the API ? And if so where ?Comment #15
webel commentedBTW I have also done a lot of direct embedding of views in .tpl.php templates for custom types, I'm quite familiar with programmatic embedding of views.
Comment #16
webel commentedFor the record, in views/includes/view.inc:
Comment #17
webel commentedIt is completely unclear to me how that (including the docs) relates to the expectation to be fed an array with two elements, the first being itself an array of referenced node nids, and the last being the nid of the page to be served into, and if that is so, then why is that not documented ?
Comment #18
joachim commentedYou need to find the actual handler file for the node ID argument handler, and find what it's getting fed to it by Views as its value.
> Separate arguments with a / as though they were a URL path.
Just what it says, so concatenate this array with slashes:
... (Array, 2 elements)
0 (String, 14 characters ) 2664,2667,2669
1 (String, 4 characters ) 2662
Comment #19
joachim commentedAre you sure you're on the latest Views? IIRC older versions didn't support multiple nids on that arg.
Comment #20
webel commentedASIDE: this is the kind of thing I am talking about (often elsewhere on Drupal.org as an ongoing theme) that drives me mad when working with Drupal code, nearly all of it, core and contributed, and it has nothing to do with PHP (which has excellent object-oriented support and class and interface handling features and the ability to design against interface contracts), at all, it is simply Drupal culture, a trick that has become an obsessive anti-pattern:
I realise fully that this code comes from Views developers, and how important that module is (and how much work it does for my life). There is absolutely no need (except for in Drupal culture) to play games like that with method names. None.
There are some nice things one can do because on can manipulate function names and pass them around, but this example above is not one of them.
Just because one can manipulate functions as names and pass them around in PHP does NOT mean that it is a good idea to always do it. The code above is essentially repeating what object-oriented structures enable us to avoid. I would like every single Drupal developer to read this and know: I don't think you, any of you, should be or need to keep doing that, and I find the way Drupal is coded so bad at times that I really have to ask seriously whether I can stay with the technology, even when it now runs many sites for me (some of which ironically teach advanced graphical object-orientation for UML+Java).
I want to, seriously, completely rewrite all of Drupal from top to bottom, because I am weary of tricks like this.
Dr Darren Kelly (Webel)
Comment #21
webel commented@ joachim
> Are you on the latest version of Views?
No. Views 6.x-2.x-dev.
> What does the node ID argument receive?
Which node ID argument of what received where ?
Please specify:module, function, line etc.
Very grateful for your persistence,
Webel
Comment #22
joachim commentedDrupal's hook system dates back to before PHP's decent OO support. I have grown to rather like the hook system myself. Besides, I'm not even sure how you'd do that pattern with OO, as the hook pattern can allow several modules to chime in and make changes.
sites/all/modules/views/modules/node/views_handler_argument_node_nid.inc
and there you are in the delights of OO, as you chase up the class tree until you find the function that actually accepts the particular argument value for that handler.
Comment #23
webel commentedAside: @joachim
> I'm not even sure how you'd do that pattern with OO
Which is probably like most Drupal developers. I do know how to do it, very elegantly and simply, and a lot more, and want to one day get every single major core developer and any contributors like you together in a room to show you better ways, ways that also bring with them incredible other powers, as well as correspondence with graphical patterns (the point being that you get to use more than just the code-friendly part of your brains, it is a cognitive matter).
Comment #24
webel commentedI will install latest views and get back ..
Comment #25
webel commented> Are you on the latest version of Views?
The latest recommended version is:
http://drupal.org/node/649642
views-6.x-2.8.tar.gz
Last updated: December 3, 2009 - 10:16
That would seem to be older than the devel version I have from:
I do not wish to re-install views now, I can recall I had to upgrade because of another problem and can't afford to influence that right now (because of client).
Could you please check for me against: views-6.x-2.8.tar.gz
I might be able to perform a check on a local version (without disrupting my client's access to the devel site) against views-6.x-2.8.tar.gz.
Comment #26
joachim commentedIn which case, your avenue is to figure out why the handler either gets the wrong data or doesn't handle it correctly.
Comment #27
webel commented@joachim With all respect and gratitude for our efforts, it is not my avenue. I am not the maintainer of your module, nor or views, and I have spent many hours now dealing with this matter (as so often lately with Drupal problems) without a solution, and the onus is not on me, and nobody could claim I have not done what I can to help myself, now can they ? I have read what a module is supposed to be able to do, I have correctly followed instructions for how I am supposed to achieve it, and it is not working. And whether it is free or not is of little interest to my paying client who would find it hard to understand why any modern system would not be able to query a database for some results and display them if there is more than one hit.
Could you please now give PRECISE instructions as to what I at my end should diagnose (having done lots already tonight), and please this time say:
WHICH handler
WHICH module
WHICH methods
You are being too vague, and it is wasting both of our time, and it costs money that I can't bill to a client.
Darren Kelly (Webel)
Comment #28
webel commentedPlease provide one example of:
A type with a reference to more than one instance of another type (the hits).
A view compatible with your module that can correctly display these many hits on referenced nodes (derived as we are instructed from the special view to be cloned).
A served web page proving that it works.
The precise combination of modules with version numbers.
Webel.
Comment #29
webel commentedjoachim wrote:
No, would YOU please concatenate this array with slashes and show me.
I asked you to please show what to feed into the Views UI preview.
The array has 2 elements, one of which is a strange string with commas between nids, so does this mean '2664,2667,2669/2662' ?
Because that certainly does not work entered in the arguments field of my view
(field_defining_document) which was cloned and adapted from your example view provided with the module.
Q: Is there anything special one has to do make that clonable example work with multiple references ?
Please provide an actual example that works. And please be precise.
Webel
Comment #30
webel commentedAll of my field_ views are cloned from the example provided by the module. Here is just one of the views I have that are not able to handle multiple node references driven by your module. Please examine it and confirm whether it should work:
Comment #31
joachim commented> @joachim With all respect and gratitude for our efforts, it is not my avenue. I am not the maintainer of your module, nor or views, and I have spent many hours now dealing with this matter (as so often lately with Drupal problems) without a solution, and the onus is not on me, and nobody could claim I have not done what I can to help myself, now can they ? I have read what a module is supposed to be able to do, I have correctly followed instructions for how I am supposed to achieve it, and it is not working. And whether it is free or not is of little interest to my paying client who would find it hard to understand why any modern system would not be able to query a database for some results and display them if there is more than one hit.
Sorry; I should have made it clear. The module works perfectly for me -- this is a support request not a bug report. I've just tried it to double-check. I've no idea how you've managed to break it. I've already given you the exact filename for the handler and a plan of attack -- it gets fed a value from the array of arguments by Views. The code may be free, but you're getting paid to figure this out; I am not and to boot I have other work to be getting on with.
Comment #32
webel commented> The code may be free, but you're getting paid to figure this out;
NO I AM NOT getting paid for it. I don't, and can't, bill this to a client. And I have spent nearly 1 month (entire month) over 6 months on this particular project, unpaid, trawling through problems that I did not cause fixing other people's problems. And most of them could have been avoided by simple object-orientation and basic defensive programming practices that are not being used enough.
Comment #33
webel commented> The module works perfectly for me
Then please now do as I have asked and show an example, with each and every element required to display multiple references.
Comment #34
webflo commentedI posted a view in http://drupal.org/node/528756#comment-2768150
Here is my setup: Node reference views 6.x-1.2 + CCK 6.x-2.6 + Views 6.x-2.8
Comment #35
webel commented@joachim
I am changing this to a bug report. Until I can see an example of it working (including version combinations) I will remain convinced it is bug (rather than that I have 'managed to break it' as you put it. It may be that I have overlooked something very simple in the use of the module, however since I don't have yet have another example to compare with there is no way of knowing.
I now find myself (again) essentially debugging within Views. If you, joachim, feel that this is a Views bug then by all means move it to the View queue, but please not before your have provided an example, instead of just insisting that it works.
> I've already given you the exact filename for the handler ...
You said (in the context of the Drupal hook system, without saying precisely how it relates to the code of this module or to this problem):
A filename is not a method, but when we (I) crack it open, one finds:
Now how please is that "a plan of attack". Am I supposed to be looking into
title_query()? Well clearly I know I am not, however I have still not been told exactly what to do. And with over 30 years coding experience, I am usually quite easy to tell what to do, the point being I know full well how to (as I have so often had to with Drupal code) trawl through it like personal tracing machine.I was told:
> What does the node ID argument receive?
I am guessing that you are referring to the above, however although this class file says that it is an 'Argument handler to accept a node id.' there is nowhere else any mention of node ids.
> Drupal's hook system dates back to before PHP's decent OO support.
Well then it is not a surprise that I find it outdated then (dare I say primitive).
> and there you are in the delights of OO
No. Never, not once, when working with Drupal, I am in the delights of OO. I adore OO. It is a major focus of my long professional career, and my entire organism at time screams for a Java CMS that has a strong community like Drupal, yet embraces delightful OO and admits use of graphical UML tools and advanced features of modern IDEs more easily, and would waste less of my time.
Comment #36
webel commentedI opened up the extended class:
And I'm none the wiser about how I can diagnose within that find out why my nodereferenceviews with multiple references only show one item.
Comment #37
webel commented@webflo
Thanks for prompt reply with precise view example and version numbers.
You wrote:
> Here is my setup: Node reference views 6.x-1.2 + CCK 6.x-2.6 + Views 6.x-2.8
I have Node reference views 6.x-1.2, Content 6.x-2.6, and Views 6.x-2.x-dev (apparently from after release of Views 6.x-2.8)
To be completely fair I will obviously now have downgrade Views back to 6.x-2.8 for precise comparison (luckily i have a local version of my remote devel site, so I can experiment a bit). Will report back.
Comment #38
webel commented@joachim
At http://drupal.org/node/528756#comment-2691600 you wrote:
Please read knowing that I appreciate your work on this module, and your attempts to help me solve "my" problem so far. I would gladly pay somebody something to help solve problems with contributed Drupal modules like this if I thought that I was going to get precise help with sufficient software engineering accuracy and instructions, and a result. The way you have tried so far to save time by not taking enough time to do that in attending to this support request (or perhaps bug) would not encourage me to do so yet with you. I recommend that you take a little bit more time to place your help remarks into a precise software engineering context, and you might find that it takes less time for everybody long term (and that is general advice for every single maintainer of a Drupal module).
Dr Darren Kelly (Webel IT Australia)
Comment #39
webel commentedI went back to Views 6.x-2.8 on an identical yet local install and it did not change anything concerning this problem, the served page still shows only one reference of many formatting using NodeReferenceViews 6.x-1.2 + CCK 6.x-2.6 + Views 6.x-2.8.
When I change the display setting for
field_defining_documentof my custom typeMethodologyfrom View to Title (link) the serves page shows the multiple referenced node links correctly.Comment #40
webel commented@joachim
The project page (there is no other documentation) states correctly:
The example view to be cloned
field_noderef_examplehas as far as I tell by defaultAllow multiple terms per argument TRUE (checked). It was not checked in the particular view I featured in this initial support request (as exported and included above), and I have no idea why. I (re)set it to true, and with the original version of this module restored it worked.You can see it working live here: http://ppi.webel.com.au/node/2662
It had nothing at all to do with any single other part of any other posting within this issue. I had written:
Well, I can't now claim that is so, somehow, at some stage, I have changed that setting
I'm sorry joachim that this has wasted your time too, however I promise I read the instructions. My view was cloned and adapted from yours, and thus should have had
Allow multiple terms per argument TRUE (checked)unless it had been changed.I've even now gone to the trouble to check that if I cloned
field_noderef_exampleit has by defaultAllow multiple terms per argument TRUE (checked)after saving. It does.I have just checked all of my field_ views, and it seems every one except the one that I have reported here
field_defining_documenthasfield_noderef_exampleit has by defaultAllow multiple terms per argument TRUE (checked).I sincerely apologise, you could not have guessed to ask to check it, because there is no reason to expect that the cloned version would have that setting changed.
Comment #41
webel commentedYou may close this after reading. I stand fully by all (other) remarks I've made in this issue report, and I hope everybody on Drupal.org reads it some day.
Proposal: every single Drupal module should have a systematic, structured, set of options that developers may/should check as "pre-conditions", and this should be served on the project page for that module.
I don't mean just as sentences within documentation (which should of course be read and checked against), I mean that a systematic record of requirements for correct operation be introduced for every module, and that this becomes a fundamental part of the module systems and generated documentation (both online, and distributed with the modules, generated).
Comment #42
joachim commented> I mean that a systematic record of requirements for correct operation be introduced for every module
That already exists: http://api.drupal.org/api/function/hook_requirements
But in the case of something like this, it would be rather onerous to check every noderef field, check it's set to display views, and dig into the view to check every setting. hook_requirements is meant more for deep-level system stuff.
> I don't mean just as sentences within documentation (which should of course be read and checked against)
Feel free start a list of those on the documentation page. I will add to it in due course.
As for my precision, I was replying to your comments while in the middle of other things. You can get prompt support, if a little rushed, or it can sink to the bottom of my pile of stuff to do and I'll get round to it when I have a wet weekend.
Comment #43
webel commented@joachim
Fair enough. I had a bad week last week (had just come out of hospital), had lost a lot of time, am late on delivering my current drupal site (due largely to delays with problem in contributed modules), and thus under a lot of pressure, and I was clearly in a stinky mood and not seeing very clearly.
Thanks for the support you do give, and for your work on this and other Drupal modules.
Please close.
Comment #44
webel commentedPS I also realise now why the view I was using was wrong. Afterwards, while I was falling asleep, I suddenly remembered I had not cloned the provided example to create the culprit view, rather I had a complex legacy view that I did not wish to repeat, and I had cloned that (some months ago), and tried to imitate the correct form for the nodereferenceviews, and obviously I had missed the multiple arguments setting on nid.
Comment #45
webel commentedjoachim wrote:
>That already exists: http://api.drupal.org/api/function/hook_requirements
A discussion of digitally controlled requirements tracing and generated requirements artifacts was commenced in the general forum: http://drupal.org/node/753556
Comment #46
giorgoskI had the same exact issue
the comment from merlin #4 solved my problem
#756344: Unable to pass multiple NID values into an argument
I personally changed the validator to simple validator
but perhaps a numeric validator would work