Hi guys!
Testing the latest dev (2011-Apr-17 ) i start getting the "error" Notice: Undefined index: tid in views_handler_field_term_node_tid->add_self_tokens() (i attach picture).
How to reproduce:
Just add a field of type: Content: All taxonomy terms & save
I track the problem to views_plugin_style (line 320 aprox. )
$this->row_tokens[$count] = $this->view->field[$id]->get_render_tokens(array());
while in the beta version is:
if ($this->uses_tokens()) {
$this->row_tokens[$count] = $this->view->field[$id]->get_render_tokens(array());
}
I haven't figure it out, why this check was removed in the latest dev version.
By including this last code again the Notice was gonne.
| Comment | File | Size | Author |
|---|---|---|---|
| #28 | fixed-undefined-index-issue-1130760-1.patch | 1.32 KB | neoglez |
| #25 | fixed-undefined-index-issue-1130760.patch | 1.24 KB | neoglez |
| #20 | views_token_error.png | 177.05 KB | mcarbone |
| #20 | test-tid-token-bug-view.txt | 5.42 KB | mcarbone |
| #4 | 1130760-tokens-add_self.patch | 592 bytes | dawehner |
Comments
Comment #1
tim.plunkettThe check was removed by this commit: http://drupalcode.org/project/views.git/commitdiff/0441fa37
Which is from this issue: #995646: Add ability to add taxonomy/term fields to node views in header/footer
Not much to be gleaned from the comments on that issue.
Comment #2
merlinofchaos commentedThe array() me be wrong in that code, as well.
Comment #3
tim.plunkettShould be enough? Fixes the notices, not sure if the problem is deeper
Comment #4
dawehnerSo what about this patch:
Comment #5
merlinofchaos commentedWell, I think it should be !empty but also, I think we can probably move that down so that it only gets called if the field id matches.
Comment #6
neoglez commentedI tested both patches (local):
failedLet's see, in the case that the array is empty the !empty works
but there are other cases where the array is not empty but it DOES NOT cotains the indexes defined for that specific Field and get_render_tokens it's still called on that Field (Field handler).Mmm, ...diferent test cases (with data in the UI "rewrite results" & without) and still there.
Comment #7
neoglez commentedOk, a lot of testing, specially verifing that the items ($item) are going to be called on the wright handler class.
Also think it's OK !empty, in principle if the item is not empty is the handler's responsability to handle it in a proper way (that's why is called handler ;-)
Patch views-1130760-3.patch solve this one.
As a curiosity: the bug can be seen online (someone forgot to turn off the error reporting in a productive env. or forgot the "use at your own risk" thing ;-)http://reliefweb.int/node/396320
Comment #8
neoglez commentedComment #9
dawehnerThanks for testing the patch. Commited to 7.x-3.x
Comment #11
mcarbone commentedYou had it right in #3: the problem is deeper.
To your "Taxonomy: All terms" field, check "Output this field as a link" and add anything in the Link path. It can contain a token or not -- either way, these same errors appear even with the fix.
Comment #12
moondancerjen commentedI can confirm that this issue is not fixed. I'm having the same problem as #11 when I try to output a taxonomy: all terms as a link.
Comment #13
dawehnertechnical viewed the problem isn't deeper , it's actually higher :)
So the problem is that views_handler_field_term_node_tid may or may not add fields to the query
which are used for the tokens.
So there are two solutions
* Always add the field to the query
* Check in in the tokens.
Any oppinions?
Comment #14
merlinofchaos commentedCheck in the tokens, probably.
Comment #15
dawehner@dereine
Can you explain what you actually talked about? views_handler_field_term_node_tid don't add tid to the query?
@mcarbone
Are you sure you have the current dev version?
Additional please provide the full error message and provide a way to reproduce the issue. A reusable export of the view would be great.
Comment #16
neoglez commentedViews is basicaly a query constructor + formating, so in this picture the roll of the fields is to add elements to the SELECT clause of the query (roughly speaking) and limiting this situation doesn't sound like a promising solution.
What does that mean exactly?
Comment #17
dawehnerPartly true, but views_handler_field_term_node_tid basically just don't add tid to the query because this would result in duplicate results, because there might be multiple terms per node.
Still needs info's
Comment #18
neoglez commentedI see the error of #11 but although they are the same (as the original) conceptually they aren't:
still applys.
Comment #19
neoglez commentedsorry :-(
Comment #20
mcarbone commented"Are you sure you have the current dev version?"
Yep.
"Additional please provide the full error message and provide a way to reproduce the issue.
Error message is same as in original post, but I've attached a screenshot. I'll rephrase the reproduction steps from #11 for clarity:
Create a page view with fields style. Add a field of type: Content: All taxonomy terms. Check "Output this field as a link" and add anything in the Link path. (It can contain a token or not.) Save and go to the view page.
"A reusable export of the view would be great."
Attached.
Comment #21
BeaPower commentedI get this error too
Comment #22
rlmumfordI got this today when grouping results by a taxonomy term
Comment #23
neoglez commentedOk, let's try to close this one.
...but first things first:
with the current dev i can not reproduce the issue any more, and it makes sense becouse following the logic in the handlers i can see what is happening:
At one point views_handler_field::advanced_render is called, then $raw_items are collected by views_handler_field_prerender_list::get_items as an array of items containig all the info needed by views_handler_field_term_node_tid::add_self_tokens (also the index tid), then comes the loop in views_handler_field::advanced_render
as it can be seen (and checked e.g. with dpm()) $alter = $item + $this->options['alter'], contains enough info when it's passed in views_handler_field::render_text to views_handler_field::get_rendered_tokens() and subsequently to views_handler_field_term_node_tid::add_self_tokens, so as far as i see it, it SHOULD be working OK.
@rlmumford now, are you using the lastest dev?? Would you post an export???
Comment #24
mcarbone commentedNope, still getting this error with the latest dev.
I already posted an export: http://drupal.org/node/1130760#comment-4600126
Comment #25
neoglez commented@mcarbone yes, you're right ;-)
The problem is that if the entity (node) in the result doesn't have any taxonomy term then $raw_items is empty, therefore views_handler_field::render_text is called only with the handler options i.e. $this->render_text($this->options['alter'] and eventually views_handler_field_term_node_tid::views_handler_field_term_node_tid() without the necesary info becouse this node doesn't have a taxonomy term. So there are different levels in wich this check (or other logic e.g. reimplementig get_items()) can be made, my opinion: since "everything" works for other handlers we should take care of it in views_handler_field_term_node_tid itself, but this is arguable. I'm also defining the token even when the entity has no term assigned, it's a less agressive approach.
Comment #26
neoglez commentedComment #27
mcarbone commentedThere's a punctuation typo on line 139 throwing an error. But patch should be fine once that's been fixed.
I wasn't sure if this was the right approach or if add_self_tokens should've been prevented from being called at all, but this is probably fine.
Comment #28
neoglez commented@mcarbone Tanks for the review
Here another one with a litter code reduction technique.
Comment #29
mcarbone commentedLooks good; errors are gone.
Comment #30
dawehnerLooks good for me as well, commited to 7.x and might be worth to backport to 6.x-3.x
Comment #31
BeaPower commentedI am getting this error in 7.x-3.0-rc1, is there a fix for this version with drupal core 7.8?
Comment #32
dawehnerPlease update to the dev version of views, it's fixed there.
Comment #33
dawehnerBackported the patch to 6.x-3.x