If you have optgroups in the select widget then the committed code from #1356112: Preserve available_options_php keys has caused the optgroups in a select widget to no longer output correctly. They now simply output as Array.

This is a serious issue as it breaks expected behaviour of the module.

CommentFileSizeAuthor
#2 select_or_other_optgroup_1.patch2.43 KBdanielb

Comments

nicholas.alipaz’s picture

Perhaps related to #1236360: Default value not working when select box uses optgroup grouping as well. Not sure where the issue is.

danielb’s picture

Status: Active » Needs review
StatusFileSize
new2.43 KB

try this

nicholas.alipaz’s picture

Status: Needs review » Needs work

that is better, but still seems to need something, each optgroup is only showing the last item in the optgroup. All other items seem to be dropped.

nicholas.alipaz’s picture

I see the issue, change this:

    if (is_array($opt)) {
      foreach ($opt as $optgroup_key => $optgroup_opt) {
        $optgroup_options = array();
        select_or_other_field_widget_form_prepare_option($optgroup_options, $optgroup_key, $optgroup_opt, $settings);
        $options[$key] = $optgroup_options;
      }
    }

To this:

    if (is_array($opt)) {
      $optgroup_options = array();
      foreach ($opt as $optgroup_key => $optgroup_opt) {
        select_or_other_field_widget_form_prepare_option($optgroup_options, $optgroup_key, $optgroup_opt, $settings);
        $options[$key] = $optgroup_options;
      }
    }

$optgroup_options = array(); needs to be outside the foreach otherwise it keeps getting reset on every iteration. Looks good once this fix is added.

danielb’s picture

Status: Needs work » Fixed

Alright cool, I've committed that, will appear in next dev.

Status: Fixed » Closed (fixed)

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

  • Commit 2db2e58 on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1532316 by danielb, nicholas.alipaz: Optgroup fix.