Invalid argument for ... when using a taxonomy term found in multiple vocabularies

netdream - May 20, 2009 - 10:13
Project:Panels
Version:6.x-3.x-dev
Component:Panel pages
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs review
Description

I've found and issue on panels module (or maybe ctools...) that appears when you try to access a panel page with an argument of type "taxonomy term", passed by title, and the same term is available on different vocabularies.

This is the error, returned n times (one for each taxonomy term in different vocabularies)
warning: Invalid argument supplied for foreach() in .../sites/all/modules/ctools/plugins/arguments/term.inc on line 49

The warning raises because in ctools "term.inc" there is:

<?php
    
case 'term':
     
$terms = taxonomy_get_term_by_name($arg);
      if (
count($terms) != 1) {
        foreach (
$terms as $potential) {
          foreach (
$conf['vids'] as $vid => $active) {
?>

count($terms) is obviously > 1 so it executes the foreach... but $conf['vids'] is not populated...

Steps to reproduce the issue:

  1. Have a term in more than one taxonomy (let's say "mydoubletaxonomyterm", different tids but same visible name)
  2. Add panel page (/admin/build/pages/panel-page/add) with path "test/%term"
  3. Assign context "Taxonomy term" -> "Term title"(not Term ID)
  4. It isn't necessary to add any content to the page...
  5. Try to access page /test/mydoubletaxonomyterm

I tried to force a single vocabulary in the panel by adding a new Context (Contexts->Add Context->Taxonomy vocabulary) and forcing one vocabulary... but it doesn't work as expected (nor it saves the choosen vocabulary in the form... maybe this is another bug...)

#1

jjemmett - June 9, 2009 - 17:10
Priority:normal» critical

I agree with the above synopsis Panels needs to provide an interface to specify the vocabulary that the term is to come from in the argument form. That interface needs to populate the $conf['vids'] variable in ctools.

#2

merlinofchaos - August 7, 2009 - 20:12

The proper way to fix this is probably to split the argument into two separate arguments, since specific config options are unwieldy. We also need more stuff like Views has where you can use taxonomy synonyms as arguments.

#3

tauno - August 20, 2009 - 22:47

Marked #551084: Same term in two taxonomies causes error in term.inc line 50 as a duplicate of this issue. The bug still exists in the 3.0 release of panels and 1.0 release of ctools.

#4

petrelharp - September 5, 2009 - 18:01

If there is no way to select which taxonomy terms are from, it is unclear what the default behavior should even be. In this case, it might be best to use tid rather than term name.

#5

mactoph - September 17, 2009 - 06:45

For reference, in my case I have duplicate terms in two different vocabularies and would like to pull content from both of those terms into a vocabulary page- that functionality works fine, but it does throw the error.

#6

petrelharp - October 21, 2009 - 18:31

Is there a workaround to make the error invisible to the end users?

#7

petrelharp - October 25, 2009 - 05:13

More information about this bug: it's turned out to be quite bad on one of my sites, since if a user adds a term to a free tagging taxonomy that is identical to one in another taxonomy (as they are wont to do), it makes error messages appear on *all* pages, even the administration pages.

  1. Inserting a call to dsm() in term.inc, it seems that for some reason, once there are identical taxonomy terms, ctools_term_context() is getting called with *that* term as an argument *twice*, on *all pages*. This isn't coming from blocks, since it's happening even on administration pages that use Garland and no blocks. This seems strange.
  2. If the taxonomies are hierarchical, this is only a problem if the terms are in the top level (perhaps, at the same level?) -- if in the free tagging taxonomy, I add a top-level (parent) term in the other vocabulary, the error occurs; but if I add a term identical to a child term in the other vocabulary, nothing happens.
  3. As a workaround, I've just removed everything inside the if clause (lines 48-58 of terms.inc). I haven't found this being a problem, anywhere. What should this break?

Hope this helps.

#8

vood002 - November 3, 2009 - 17:48

@petrelharp: Just change your error reporting settings at admin/settings/error-reporting

Or...in other words...subscribing

#9

dalin - November 9, 2009 - 06:27

@petrelharp a safer workaround is to change the if line to
if (count($terms) > 1) {
That way the original handling of when count($terms) == 1 is still retained.

I'm submitting this as a patch for someone who knows what this function does to review. I too find it disconcerting that this function is being called on every page, even the admin section.

AttachmentSize
ctools_foreach_error.diff 539 bytes

#10

dalin - November 9, 2009 - 06:27
Status:active» needs review
 
 

Drupal is a registered trademark of Dries Buytaert.