Currently forms are selected through a css ID, e.g., user-register-form. For some forms this presents issues, e.g., node-form applies to all node forms rather than forms for specific node types.

Attached patch (versions for both HEAD and D6) adds support for form ids in the form e.g. article_node_form. Approach:

* Change relevant settings form #description to explain both CSS and form_id formats, with examples.
* Extend jquery selectors to include form:has([value=form_id]).

Comments

sun’s picture

Um. Are you really sure? ;)

function compact_forms_form_alter(&$form, $form_state, $form_id) {
  static $css_ids, $form_ids, $loaded, $field_size, $descriptions;

  // Prepare CSS form ids.
  if (!isset($css_ids)) {
    $css_ids = explode("\n", variable_get('compact_forms_ids', 'user-login-form'));
    $css_ids = array_filter(array_map('trim', $css_ids));
  }
  // Prepare Form API form ids.
  if (!isset($form_ids) && !empty($css_ids)) {
    $form_ids = array();
    foreach ($css_ids as $id) {
      $form_ids[] = strtr($id, array('-' => '_'));
    }
  }
sun’s picture

Status: Needs review » Postponed (maintainer needs more info)
nedjo’s picture

Status: Postponed (maintainer needs more info) » Needs review

Pretty sure, yes ;)

True, underscores are changed to hyphens in the $form_ids variable array, but it's the original $css_ids that is tested in (isset($form['#id']) && in_array($form['#id'], $css_ids)) and that's sent to Drupal.settings: _compact_forms_include_js($css_ids);.

To verify that the patch works, put e.g. page_node_form as a value in the configuration variable. On my testing, this triggers the compact forms behaviour for page_node_form.