Skip to content

Update the part in the documentation comment about array_filter #6303

Open
backdrop/backdrop
#4589
@avpaderno

Description

@avpaderno

system_settings_form_submit() has the following documentation comment.

/**
 * Form submission handler for system_settings_form().
 *
 * If you want node type configure style handling of your checkboxes,
 * add an array_filter value to your form.
 *
 * @since 1.6.0 Restored and made compatible with configuration management.
 */

The part about the array_filter value is true only for forms that do not define $form['#config'] and when the Drupal compatibility layer is enabled, since that function uses the following code. (The comments in the code are mine.)

  if (!empty($form['#config'])) {
    $configs = _system_sort_form_values_by_config($form, $form_state, $form['#config']);
    foreach ($configs as $bucket => $data) {
      config_set_multiple($bucket, $data);
    }
  }
  else {
    watchdog('form', 'Backdrop 2.0 and later will require forms using system_settings_form() to set $form[\'#config\'].', array(), WATCHDOG_DEPRECATED);
    if (!settings_get('backdrop_drupal_compatibility')) {
      backdrop_set_message(t('Settings not saved: Drupal compatibility layer is disabled and this form has not been updated to use Backdrop configuration management.'), 'error');
      return;
    }

    // The form does not set a value for $form['#config'] and the Drupal compatibility layer
    // is enabled.
    foreach ($form_state['values'] as $key => $value) {
      if (is_array($value) && isset($form_state['values']['array_filter'])) {
        $value = array_keys(array_filter($value));
      }
      variable_set($key, $value);
    }
  }

Either that documentation comment is changed to make clear 'array_filter' is used when the Drupal compatibility layer is enabled, and the form does not set $form['#config'], or the code is changed to handle 'array_filter' in all the cases.

IMO, 'array_filter' should only be used for BC with Drupal 7. I would rather change the documentation comment to reflect that.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions