You are here

function dialog_fix_element_id in Dialog 7

Fix element and its chilren's id's so they are unique in the page.

1 call to dialog_fix_element_id()
dialog_process_ajax_form in ./dialog.module
Process a form and prepare it for the dialog.

File

./dialog.module, line 144
The Dialog module provides an API for displaying and interacting with jQuery UI Dialog modals.

Code

function dialog_fix_element_id(&$element) {
  if (!isset($element['#id'])) {
    $element['#id'] = drupal_html_id('edit-' . implode('-', $element['#parents']));
  }
  $element['#id'] .= '-dialog';
  foreach (element_children($element) as $child) {

    // Don't squash an existing tree value.
    if (!isset($element[$child]['#tree'])) {
      $element[$child]['#tree'] = $element['#tree'];
    }

    // Don't squash existing parents value.
    if (!isset($element[$child]['#parents'])) {

      // Check to see if a tree of child elements is present. If so,
      // continue down the tree if required.
      $element[$child]['#parents'] = $element[$child]['#tree'] && $element['#tree'] ? array_merge($element['#parents'], array(
        $child,
      )) : array(
        $child,
      );
    }
    dialog_fix_element_id($element[$child]);
  }
}