I have 3-levels taxonomy (country-region-city).
When I select 1 or 2 level - I have empty selectbox (see picture) and following errors:

Location (all errors): http://xn--80adxhks.xn--80adxhks.xn----7sblvlgns.xn--p1ai/hierarchical_s...

Notice: Undefined offset: 2 in _hierarchical_select_hierarchy_validate() (line 1972 of /DATA/home-sites/lib/modules_common/for_all_projects/hierarchical_select/hierarchical_select.module).

Notice: Undefined offset: 2 in _hierarchical_select_hierarchy_validate() (line 1975 of /DATA/home-sites/lib/modules_common/for_all_projects/hierarchical_select/hierarchical_select.module).

Notice: Undefined offset: 3 in _hs_process_render_hs_selects() (line 1168 of /DATA/home-sites/lib/modules_common/for_all_projects/hierarchical_select/hierarchical_select.module).

Warning: Invalid argument supplied for foreach() in _hierarchical_select_options() (line 390 of /DATA/home-sites/lib/modules_common/for_all_projects/hierarchical_select/includes/theme.inc).

It is right after I install 18 november dev.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

super_romeo’s picture

More. It works OK every second select time: Not works, works, not works, works...

stefan.r’s picture

@super_romeo do you still have this issue in the latest dev version?

Also see #2382287: Hierarchical Select Taxonomy

super_romeo’s picture

Hi! Thanks for attention.

No changes.
And one more thing.
I have 4 websites with same error (on same LINUX server).
BUT on 2 different local computers (windows) it works fine!
Same DB dump and code.
I'm impressed.

Server:
Linux: gentoo
nginx 1.7.6
php 5.5.18
mysql 5.5.40

super_romeo’s picture

Check it: http://сдай-лом.рф/en/node/add/ads-sell

AND. Now I use "Save term lineage" and if select "Save only the deepest term" all is OK. But I need lineage.

calculus’s picture

Kind of same issue here.

In order to fix "update button" problem i tried patch below

#828418-41: Drupal.attachBehaviors() used with an incorrect context?

I just replaced
Drupal.attachBehaviors(Drupal.HierarchicalSelect.context);
with
Drupal.attachBehaviors($('#hierarchical-select-' + hsid + '-wrapper').parents('div.form-item'));

It worked locally (windows) but i had offset notices at a linux server.

I applied the patch to alpha6 and alpha8. Same behavior. Probably there is nothing to do with the security update.
I have not tried with dev version.

super_romeo’s picture

Thanks, calculus!

1. But, there is no "update button" problem in my case :)
2. I can't find "Drupal.attachBehaviors(Drupal.HierarchicalSelect.context);" string in code...

calculus’s picture

I am not sure how those two problems are connecting... I m guessing its a javascript problem.

I just informed stefan.r that changing the javascript code, leads to the same behavior as yours. Empty boxes, offset notices and "working - not working" behavior.

Btw look at hierarchical_select.js

stefan.r’s picture

@super_romeo, I see the issue on your site but I cannot reproduce it locally. The string is not in the code because the patch @calculus mentions is already in the dev version. It suggests that patch may cause the issue somehow. Possibly by referring to incorrect HSIDs, which in turn is possibly introduced by the patch committed from this issue: #1349868: Issues when Hierarchecal Select is inside Field Collection.

These are all just wild guesses though, so perhaps you can send me a dump of a stripped down dump of a site with this issue (without any extra modules/themes, ideally just 1 simple content type with this issue and a vocabulary). You can contact me through my user profile. Alternatively I would need a way to reproduce this issue on a fresh drupal install.

Lastly, just to see whether it really is this patch causing the issue, does the odd behavior disappear when you apply the attached patch?

stefan.r’s picture

As to the windows/linux issue, just to see whether the problem might be the PHP version, are you using the same php version on windows (ie 5.5?)

super_romeo’s picture

Local server:
Windows: 8.1
Apache: 2.4
php 5.5
mysql 5.5

I've apply patch on latest dev (5 dec) - no result.
I'll send you access to my website in private massage.

super_romeo’s picture

Сalculus, thanks!

dode’s picture

I have the same problem,

When I change the 'Level choice' option from 'Force the user to choose a term from a deepest level' to 'Allow the user to choose a term from any level' in field 'Widget Type' settings, it's work ok for me without warnings and error.

I miss the 'help-text' which should be underneath the 'update' button.

thaknks,
Martin

stefan.r’s picture

stefan.r’s picture

As to the windows/linux issue - this seems to be due to different PHP versions.

With PHP 5.3.34 I don't have the issue and with PHP 5.4.34/5.5.18 I do have it.

stefan.r’s picture

Title: Notice: Undefined offset: xxx in _hierarchical_select_hierarchy_validate() » Multi-level taxonomies behaving erratically in newer PHP versions (undefined offset in _hierarchical_select_hierarchy_validate())
FileSize
636 bytes

So the issue seems to be that after after removing an index from the end of the $selections array using unset() in _hierarchical_select_hierarchy_validate(), the next index value will still be what it would have been.

Later on we do $hierarchy->lineage = $selection;, and in newer versions of PHP the same will apply to $hierarchy->lineage, ie the next index value will be what it would have been in $selection.

Ie:


$selection = array(
0 => 1,
1 => 2,
2 => 3,
);
unset($selection[2]);
$hierarchy->lineage = $selection;
$hierarchy->lineage[] = 4;

In newer versions of PHP this would give:

$hierarchy->lineage[] == array(
0 => 1,
1 => 2,
3 => 4,
);

We'd need the index for the new element to be 2, not 3. The attached patch should fix this.

stefan.r’s picture

Status: Active » Needs review

  • stefan.r committed 5fbe7fe on 7.x-3.x
    Issue #2382655 by stefan.r, super_romeo: Multi-level taxonomies behaving...

  • stefan.r committed d9e48ee on 7.x-3.x
    Issue #2382655 by stefan.r, super_romeo: Multi-level taxonomies behaving...
stefan.r’s picture

Status: Needs review » Fixed
coolman7’s picture

I'm using 7.x-3.0-alpha9 version and PHP 5.5.9-1ubuntu4.5. And I still have problems with multi level taxonomy terms. I can only select first level of terms.

stefan.r’s picture

@coolman7, that's another issue. You have the same problem with Alpha8?

coolman7’s picture

yes. I had same issue with alpha8.

coolman7’s picture

Is there any solution for this issue? Or is there any open case for that one? So I should post to correct issue.

Status: Fixed » Closed (fixed)

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

kristiaanvandeneynde’s picture

I just spent somewhere between 2 and 3 hours debugging this and came to the same conclusion as stefan.r in #15: The line $lineage[] = $first_child; in _hierarchical_select_hierarchy_enforce_deepest() causes an index jump every other time it's run.

Using array_values() is the proper fix here, although it's kind of concerning that the code relies on the order of a numerical index. Especially given how "volatile" these are, q.e.d.