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.

Comments

tim.plunkett’s picture

The 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.

merlinofchaos’s picture

The array() me be wrong in that code, as well.

tim.plunkett’s picture

Status: Active » Needs review
StatusFileSize
new590 bytes

Should be enough? Fixes the notices, not sure if the problem is deeper

dawehner’s picture

StatusFileSize
new592 bytes

So what about this patch:

merlinofchaos’s picture

Well, 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.

neoglez’s picture

I tested both patches (local):

views-1130760-3.patch failed
1130760-tokens-add_self.patch failed

Let'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.

neoglez’s picture

Status: Fixed » Needs review

Ok, 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

neoglez’s picture

Status: Needs review » Reviewed & tested by the community
dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for testing the patch. Commited to 7.x-3.x

Status: Needs review » Closed (fixed)

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

mcarbone’s picture

Status: Closed (fixed) » Active

You 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.

moondancerjen’s picture

I 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.

dawehner’s picture

technical 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?

merlinofchaos’s picture

Check in the tokens, probably.

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)

@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.

neoglez’s picture

Status: Postponed (maintainer needs more info) » Active

Views 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.

Check in the tokens

What does that mean exactly?

dawehner’s picture

Status: Active » Postponed (maintainer needs more info)
Views 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.

Partly 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

neoglez’s picture

Status: Postponed (maintainer needs more info) » Active

I see the error of #11 but although they are the same (as the original) conceptually they aren't:

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

still applys.

neoglez’s picture

Status: Active » Postponed (maintainer needs more info)

sorry :-(

mcarbone’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new5.42 KB
new177.05 KB

"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.

BeaPower’s picture

I get this error too

rlmumford’s picture

I got this today when grouping results by a taxonomy term

neoglez’s picture

Status: Active » Postponed (maintainer needs more info)

Ok, 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

foreach ($raw_items as $count => $item) {
          $value = $this->render_item($count, $item);
          if (is_array($value)) {
            $value = drupal_render($value);
          }
          $this->last_render = $value;
          $this->original_value = $this->last_render;
dpm($item);
          $alter = $item + $this->options['alter'];
          $items[] = $this->render_text($alter);
        }

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???

mcarbone’s picture

Status: Postponed (maintainer needs more info) » Active

Nope, still getting this error with the latest dev.

I already posted an export: http://drupal.org/node/1130760#comment-4600126

neoglez’s picture

StatusFileSize
new1.24 KB

@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.

neoglez’s picture

Status: Active » Needs review
mcarbone’s picture

Status: Needs review » Needs work

There'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.

neoglez’s picture

Status: Needs work » Needs review
StatusFileSize
new1.32 KB

@mcarbone Tanks for the review
Here another one with a litter code reduction technique.

mcarbone’s picture

Status: Needs review » Reviewed & tested by the community

Looks good; errors are gone.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Looks good for me as well, commited to 7.x and might be worth to backport to 6.x-3.x

BeaPower’s picture

I am getting this error in 7.x-3.0-rc1, is there a fix for this version with drupal core 7.8?

dawehner’s picture

Please update to the dev version of views, it's fixed there.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Backported the patch to 6.x-3.x

Status: Fixed » Closed (fixed)

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