You are here

function summarize_element in Ubercart 6.2

Summarize an individual element using its specified #summary if possible.

Parameters

$form: The element's array in the form array.

$title: TRUE or FALSE indicating whether or not to include the element's #title in the summary text.

Return value

A summary string for the element or a summary array for a fieldset.

1 string reference to 'summarize_element'
summarize_form in uc_store/includes/summaries.inc
Summarizes the elements in a form array.

File

uc_store/includes/summaries.inc, line 70
Provides summaries of forms and fieldsets.

Code

function summarize_element($form, $title = FALSE) {

  // Check to see if the form array contained a #summary.
  if (isset($form['#summary'])) {

    // If so, decide whether to display it with or without the element's #title.
    if ($title) {
      return t('!title: !summary', array(
        '!title' => $form['#title'],
        '!summary' => $form['#summary'],
      ));
    }
    else {
      return $form['#summary'];
    }
  }
  elseif (isset($form['#type'])) {

    // Otherwise, use a sensible default based on the field type.
    switch ($form['#type']) {
      case 'fieldset':
        return array(
          array(
            'data' => $form['#title'] . ':',
            'children' => summarize_form($form),
          ),
        );
      case 'textfield':
        return $form['#title'] . ': ' . check_plain($form['#default_value']);
      case 'select':
        if (!empty($form['#multiple']) and is_array($form['#default_value'])) {
          $options = array();
          foreach ($form['#default_value'] as $value) {
            if (isset($form['#options'][$value])) {
              $options[] = $form['#options'][$value];
            }
          }

          // Return an item list of the selected options.
          return array(
            array(
              'data' => $form['#title'] . ':',
              'children' => $options,
            ),
          );
        }

      // Else, fall through.
      case 'radios':
        return $form['#title'] . ': ' . $form['#options'][$form['#default_value']];
      case 'checkbox':
        if ($form['#default_value'] && isset($form['#title'])) {
          return $form['#title'];
        }
        else {
          return;
        }
    }

    // If we didn't have a default action, check for a callback.
    $callback = 'summarize_' . $form['#type'];
    if (function_exists($callback)) {
      return $callback($form);
    }
  }
}