If both Betterselect and Node Form Rearrange modules are active on same node it will produce error after saving edited node:
warning: Invalid argument supplied for foreach() in /var/www/vhosts/testsite/httpdocs/sites/all/modules/betterselect/betterselect.module on line 227.

CommentFileSizeAuthor
#1 betterselect.module.patch484 bytesMac Clemmens

Comments

Mac Clemmens’s picture

StatusFileSize
new484 bytes

Because other modules can change $form_state['values']['taxonomy'], it is important to check that values are loaded as an array before trying to run a foreach() function.

Adding a check before proceeding is one way to solve the problem:

  if (!is_array($form_state['values']['taxonomy'])) {
    return;
  }

Patch attached applies to line ~223 of betterselect.module


/**
 * Restore submitted checkbox values back to format Taxonomy module expects.
 */
function betterselect_taxonomy_from_checkboxes($form, &$form_state) {
  if (!is_array($form_state['values']['taxonomy'])) {
    return;
  }
  foreach ($form_state['values']['taxonomy'] as $index => $properties) {
    if (is_numeric($index) && $form['taxonomy'][$index]['#multiple']) {
      $options = array();
      foreach ($form_state['values']['taxonomy'][$index] as $tid => $selected) {
        if ($selected) {
          $options[$tid] = $tid;
          // Save lineage - automatically select all parents.
          if (variable_get('betterselect_save_lineage', FALSE)) {
            $parents = taxonomy_get_parents($tid);
            foreach ($parents as $key => $val) {
              $options[$key] = $key;
            }
          }
        }
      }
      $form_state['values']['taxonomy'][$index] = $options;
    }
  }
}

Mac Clemmens’s picture

Status: Active » Needs review
prophet108’s picture

Thank you for posting this!