diff --git a/hierarchical_select.module b/hierarchical_select.module index 120eedb..f3edd7d 100644 --- a/hierarchical_select.module +++ b/hierarchical_select.module @@ -25,7 +25,7 @@ function hierarchical_select_menu() { 'theme callback' => 'ajax_base_page_theme', 'type' => MENU_CALLBACK, ); - + $items['admin/config/content/hierarchical_select'] = array( 'title' => 'Hierarchical Select', 'description' => 'Configure site-wide settings for the Hierarchical Select form element.', @@ -360,7 +360,7 @@ function _hs_process_attach_css_js($element, $hsid, &$form_state, $complete_form $element['#attached']['library'][] = array('system', 'drupal.ajax'); $element['#attached']['library'][] = array('system', 'jquery.form'); $element['#attached']['library'][] = array('system', 'effects'); - $element['#attached']['library'][] = array('system', 'effects.drop'); + $element['#attached']['library'][] = array('system', 'effects.drop'); $element['#attached']['css'][] = drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select.css'; $element['#attached']['js'][] = drupal_get_path('module', 'hierarchical_select') . '/hierarchical_select.js'; if (variable_get('hierarchical_select_js_cache_system', 0) == 1) { @@ -470,7 +470,7 @@ function _hs_process_developer_mode_log_selections($config, $hs_selection, $db_s } } -function _hs_process_developer_mode_log_hierarchy_and_dropbox($config, $hierarchy, $dropbox) { +function _hs_process_developer_mode_log_hierarchy_and_dropbox($config, $hierarchy, $dropbox) { if (HS_DEVELOPER_MODE) { _hierarchical_select_log('Generated hierarchy in ' . $hierarchy->build_time['total'] . ' ms:'); _hierarchical_select_log($hierarchy); @@ -648,7 +648,7 @@ function _hs_process_render_dropbox($element, $hsid, $creating_new_item, $dropbo '#attributes' => array('class' => array('add-to-dropbox')), '#limit_validation_errors' => array($element['#parents']), '#validate' => array(), - '#submit' => array('hierarchical_select_ajax_update_submit'), + '#submit' => array('hierarchical_select_ajax_update_submit'), ); } @@ -662,7 +662,7 @@ function _hs_process_render_dropbox($element, $hsid, $creating_new_item, $dropbo // Disable all child form elements of $element['hierarchical_select]. // _hierarchical_select_mark_as_disabled($element['hierarchical_select']); - + // TODO: make the above work again. Currently, we're just disabling // the "Add" button. #disabled can't be used for the same reasons as // described in _hierarchical_select_mark_as_disabled(). @@ -675,7 +675,7 @@ function _hs_process_render_dropbox($element, $hsid, $creating_new_item, $dropbo if (isset($dropbox->lineages_selections)) { $form_state['storage']['hs'][$hsid]['dropbox_lineages_selections'] = $dropbox->lineages_selections; } - + // Add the dropbox-as-a-table that will be visible to the user. $element['dropbox']['visible'] = _hs_process_render_db_table($hsid, $dropbox); } @@ -1006,7 +1006,7 @@ function _hierarchical_select_process_get_hs_selection($element) { * An array (bag) containing the ids of the selected items in the * dropbox. */ -function _hierarchical_select_process_get_db_selection($element, $hsid, $form_state) { +function _hierarchical_select_process_get_db_selection($element, $hsid, &$form_state) { $db_selection = array(); if (!empty($form_state['storage']['hs'][$hsid]['dropbox_lineages_selections'])) { @@ -1017,6 +1017,11 @@ function _hierarchical_select_process_get_db_selection($element, $hsid, $form_st if ($remove_value['remove'] === '1') { // $x is of the form "lineage-". Extract the number. $remove_from_db_selection[] = substr($x, 8); + // By removing the input (POST) reference to the remove checkbox, + // we make sure that on a form rebuilt, the same remove checkbox, + // which is accessed by index, is not set, preventing a double removal + // @see https://www.drupal.org/node/1566878#comment-9226261 + unset($form_state['input']['parent']['dropbox']['visible']['lineages'][$x]['remove']); } } } @@ -1075,7 +1080,7 @@ function _hierarchical_select_process_get_db_selection($element, $hsid, $form_st * @see _hierarchical_select_hierarchy_generate() * @see _hierarchical_select_dropbox_generate() */ -function _hierarchical_select_process_calculate_selections(&$element, $hsid, $form_state) { +function _hierarchical_select_process_calculate_selections(&$element, $hsid, &$form_state) { $hs_selection = array(); // hierarchical select selection $db_selection = array(); // dropbox selection @@ -1086,7 +1091,7 @@ function _hierarchical_select_process_calculate_selections(&$element, $hsid, $fo // - no input data was provided (through POST nor GET) // - or #value is set directly and not by a Hierarchical Select POST (and // therefor set either manually or by another module), - // then use the value of #default_value, or when available, of #value. + // then use the value of #default_value, or when available, of #value. if (empty($form_state['input']) || (!isset($element['#value']['hierarchical_select']) && !isset($element['#value']['dropbox']))) { $value = (!empty($element['#value'])) ? $element['#value'] : $element['#default_value']; $value = (is_array($value)) ? $value : array($value); @@ -1470,7 +1475,7 @@ function _hierarchical_select_mark_as_disabled(&$element) { // for UI purposes only, but still allow input to be processed if it's // sumitted, it can set the desired attribute in #attributes directly // rather than using #disabled." - // #disabled prevents #value from containing values for disabled elements, + // #disabled prevents #value from containing values for disabled elements, // but using #attributes circumvents this. Most likely, Form API thinks that // because HS' selects are disabled, that the whole of HS is disabled (which // is of course a wrong assumption). Hence it thinks the 'op' that is being