* Notice : Undefined index: allowed_values in hs_taxonomy_form_field_ui_field_edit_form_alter() (line 143 in (...)/sites/all/modules/hierarchical_select/modules/hs_taxonomy.module).
    * Notice : Trying to get property of non-object in hs_taxonomy_form_field_ui_field_edit_form_alter() (line 144 in (...)/sites/all/modules/hierarchical_select/modules/hs_taxonomy.module).

Steps to reproduce :
Install hierarchical_select 7.x-3.0-alpha1
Create any field save the first form, the error will show up.

Steps I followed :
created a location field in a profile2 profile type. When you save the field the error message pops up. I tried with a location field in a content type, it was the same, so it's not related to profile2.
Then I tried with a text field and the same error appears.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Eaglecanada’s picture

I have the same error message. After disable the HS module, it is back to normal.

Hamid.D’s picture

Same problem

Kcannick’s picture

subscribe

webankit’s picture

same problem...

Jerome F’s picture

Version: 7.x-3.0-alpha1 » 7.x-3.x-dev

The notice now points to lines 142 and 143 in 7.x-3.x-dev

yugongtian’s picture

+1

SolidRock’s picture

Having the same problem. I did notice that it only appears when you *don't* use a hierarchical-select widget. If you do use the HS widget, the notice doesn't appear.

fietserwin’s picture

Title: Notice for HS taxonomy module » Notice : Undefined index: allowed_values in hs_taxonomy_form_field_ui_field_edit_form_alter()

Writing clear and precise titles improves searchability.

Jerome F’s picture

@fietserwin: thank you, you're right I should have done that.
@SolidRock: that's true.

fietserwin’s picture

Status: Active » Needs review

The hook is executed for all fields, also non taxonomy fields. So it looks like there should be a simple check added around the code:

old:

function hs_taxonomy_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';

  $vocabulary = taxonomy_vocabulary_machine_name_load($form['#field']['settings']['allowed_values'][0]['vocabulary']);
  $config = hierarchical_select_common_config_get("taxonomy-$vocabulary->vid");

  if ($config['dropbox']['status'] || $config['save_lineage']) {
    $form['field']['cardinality']['#disabled'] = TRUE;
    $form['field']['cardinality']['#description'] .= ' <strong>' . t('This setting is now managed by the Hierarchical Select configuration.') . '</strong>';
  }
}

new:

function hs_taxonomy_form_field_ui_field_edit_form_alter(&$form, &$form_state) {
  if (isset($form['#field']['settings']['allowed_values'][0]['vocabulary'])) {
    require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'hierarchical_select') . '/includes/common.inc';

    $vocabulary = taxonomy_vocabulary_machine_name_load($form['#field']['settings']['allowed_values'][0]['vocabulary']);
    $config = hierarchical_select_common_config_get("taxonomy-$vocabulary->vid");

    if ($config['dropbox']['status'] || $config['save_lineage']) {
      $form['field']['cardinality']['#disabled'] = TRUE;
      $form['field']['cardinality']['#description'] .= ' <strong>' . t('This setting is now managed by the Hierarchical Select configuration.') . '</strong>';
    }
  }
}

However, I have some other remarks about the code:
- Wouldn't it be better to replace require_once with module_load_include('inc', 'hierarchical_select', 'includes/common')?
- for clarity it would be better to use curly brackets in the string "taxonomy-$vocabulary->vid" : "taxonomy-${vocabulary->vid}"

So no patch, The change is easy enough, to allow the module maintainer to create it himself and at the same time incorporating (or not) my suggestions.

Adam S’s picture

Same problem. #10 fixed it.

ymazigo’s picture

thanks.#10 fix my problem

geerlingguy’s picture

Git patch attached. To apply: Put patch into hs folder (not the modules subfolder), and enter in terminal: git apply -v [patchname.patch].

dafeder’s picture

#13 worked for me - also, this works fine with the standard patch command patch -p1 < fix_undefined_index-1115498-13.patch.

WorldFallz’s picture

Status: Needs review » Reviewed & tested by the community

simple patch, applies cleanly, fixes the problem.

carwin’s picture

#13 works for me too, this should be added to the module perhaps?

glass.dimly’s picture

+1 works for me too.

spessex’s picture

To get this to patch I had to save the patch to the modules subfolder of HS and then apply the patch by issuing the following command:

cd [space] then file path of modules subfolder - just drag and drop from finder into terminal.

in my example:

cd /Applications/MAMP/htdocs/mrfgr/sites/all/modules/hierarchical_select/modules

followed by:

patch < fix_undefined_index-1115498-13.patch

This then works.

Wim Leers’s picture

Status: Needs review » Fixed

@fietserwin: solid suggestions, but:
1) I don't know if there was a particular reason for me to do this: maybe it's a leftover from the D5 days, maybe it's because module_load_include() is not available in AJAX calls — I don't remember. Hence, I will not make this change right away, but I welcome a patch that does this (in a separate issue).
2) Personally, I don't think it's particularly more legible that way — maybe it depends on your editor's syntax highlighting?

@spessex: alternatively, you could just use `git apply

Committed the patch in #13 by geerlingguy: http://drupalcode.org/project/hierarchical_select.git/commit/d6b991a

fietserwin’s picture

Status: Reviewed & tested by the community » Needs review

Hmmm, I'm still getting the 2nd notice:

Notice: Trying to get property of non-object in hs_taxonomy_form_field_ui_field_edit_form_alter() (line 144 of D:\Projecten\Maisonnera\public_html\sites\all\modules\hierarchical_select\modules\hs_taxonomy.module).

It turns out there are fields that have $form['#field']['settings']['allowed_values'][0] set, and that contain a string (fields with type = list_integer). So $form['#field']['settings']['allowed_values'][0]['vocabulary'] will then return the first character of that string, which is set...

I think it will be better to check on the type of the field:

  if (isset($form['#field']['type']) && $form['#field']['type'] === 'taxonomy_term_reference') {
   ...
 }
Wim Leers’s picture

Good catch. Committed your suggestion: http://drupalcode.org/project/hierarchical_select.git/commit/e14b895. Thanks again!

Status: Fixed » Closed (fixed)

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