You are here

function rules_forms_add_popups in Rules Forms Support 7

Create element information popups for each element of a form.

This function is only called if the current session has the setting enabled.

Parameters

mixed $form: The form currently being viewed.

mixed $elements: An array of element info for the form being viewed.

1 call to rules_forms_add_popups()
rules_forms_after_build in ./rules_forms.module
Add element IDs on the form if the setting is enabled.

File

./rules_forms.module, line 342
Rules Forms Support provides events, conditions, and actions for site forms.

Code

function rules_forms_add_popups(&$form, $elements) {
  $help = t('Note: The circle symbol indicates an array (multiple value) property.');
  foreach ($elements as $element_id => $info) {
    $element =& _rules_forms_get_element($form, $element_id);

    // For fieldsets we have to use the suffix instead of the title.
    $attribute = isset($element['#type']) && ($element['#type'] == 'fieldset' || $element['#type'] == 'radio' || $element['#type'] == 'checkbox') ? '#prefix' : '#title';

    // Add the element inspection popup image.
    if (isset($element['#title'])) {
      if (isset($element['#type']) && $element['#type'] == 'checkbox') {
        $element[$attribute] = '<a href="#" class="rules-forms-inspection-link" style="position:relative;top:22px;right:22px;"></a>';
      }
      elseif (isset($element['#type']) && $element['#type'] == 'radio') {
        $element[$attribute] = '<a href="#" class="rules-forms-inspection-link" style="position:relative;top:28px;right:22px;"></a>';
      }
      else {
        $element[$attribute] = $element['#title'] . '<a href="#" class="rules-forms-inspection-link"></a>';
      }
    }
    else {
      $element[$attribute] = ucfirst(str_replace('_', ' ', $element['#type'])) . '<a href="#" class="rules-forms-inspection-link"><span class="rules-forms-inspection-image"></span></a>';
    }
    $element[$attribute] .= '<div class="rules-forms-element-inspection">' . '<span class="rules-forms-element-label"><h3>' . $info['label'] . '</h3></span>' . '<table width="100%" border="0" cellpadding="2" class="rules-forms-inspection">' . '<thead><tr><th>Attribute</th><th>Value</th></tr></thead>';

    // Each value calls the display function which will recursively print
    // attribute information.
    $line = 'odd';
    $reject_elements = array(
      '#node',
      '#entity',
    );
    foreach ($element as $key => $value) {
      if ($key !== $attribute && element_property($key) && !in_array($key, $reject_elements)) {

        // Print the attribute type and value table cells.
        $element[$attribute] .= '<tr class="' . $line . '"><td class="rules-forms-element-type">' . ucfirst(str_replace(array(
          '#',
          '_',
        ), array(
          '',
          ' ',
        ), $key)) . ':</td><td class="rules-forms-element-value">';

        // Compile the attribute value.
        _rules_forms_display_info($element[$attribute], $value);
        $element[$attribute] .= '</td></tr>';
        $line = $line == 'odd' ? 'even' : 'odd';
      }
    }
    $element[$attribute] .= '</table><span class="rules-forms-info-help">' . $help . '</span></div>';
  }
}