[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/elements/ -> elements.theme.inc (source)

   1  <?php
   2  
   3  /**
   4   * @file
   5   * The theme include file for the elements module.
   6   *
   7   * Contains the theme functions for all the elements module elements.
   8   */
   9  
  10  /**
  11   * Returns HTML for a table with radio buttons or checkboxes.
  12   *
  13   * An example of per-row options:
  14   * @code
  15   * $options = array();
  16   * $options[0]['title'] = "A red row"
  17   * $options[0]['#attributes'] = array ('class' => array('red-row'));
  18   * $options[1]['title'] = "A blue row"
  19   * $options[1]['#attributes'] = array ('class' => array('blue-row'));
  20   *
  21   * $form['myselector'] = array (
  22   * '#type' => 'tableselect',
  23   * '#title' => 'My Selector'
  24   * '#options' => $options,
  25   * );
  26   * @endcode
  27   *
  28   * @param $element
  29   *   An associative array containing the properties and children of the
  30   *   tableselect element. Properties used: #header, #options, #empty, and
  31   *   #js_select. The #options property is an array of selection options; each
  32   *   array element of #options is an array of properties. These properties can
  33   *   include #attributes, which is added to the table row's HTML attributes;
  34   *   see theme_table().
  35   *
  36   * @ingroup themeable
  37   */
  38  function theme_tableselect($element) {
  39    $rows = array();
  40    $header = $element['#header'];
  41    if (!empty($element['#options'])) {
  42      // Generate a table row for each selectable item in #options.
  43      foreach (element_children($element) as $key) {
  44        $row = array();
  45  
  46        $row['data'] = array();
  47        if (isset($element['#options'][$key]['#attributes'])) {
  48          $row += $element['#options'][$key]['#attributes'];
  49        }
  50  
  51        // Render the checkbox / radio element.
  52        $element[$key]['#printed'] = NULL;  // Drupal 6 only
  53        $row['data'][] = drupal_render($element[$key]);
  54  
  55        // As theme_table only maps header and row columns by order, create the
  56        // correct order by iterating over the header fields.
  57        foreach ($element['#header'] as $fieldname => $title) {
  58          $row['data'][] = $element['#options'][$key][$fieldname];
  59        }
  60        $rows[] = $row;
  61      }
  62      // Add an empty header or a "Select all" checkbox to provide room for the
  63      // checkboxes/radios in the first table column.
  64      if ($element['#js_select']) {
  65        // Add a "Select all" checkbox.
  66        //drupal_add_js('misc/tableselect.js');
  67        //array_unshift($header, array('class' => 'select-all'));
  68        array_unshift($header, theme('table_select_header_cell')); // Drupal 6 only
  69      }
  70      else {
  71        // Add an empty header when radio buttons are displayed or a "Select all"
  72        // checkbox is not desired.
  73        array_unshift($header, '');
  74      }
  75    }
  76  
  77    // Add the 'empty' row message if available.
  78    if (!count($rows) && $element['#empty']) {
  79      $header_count = 0;
  80      foreach ($header as $header_cell) {
  81        if (is_array($header_cell)) {
  82          $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1;
  83        }
  84        else {
  85          $header_count++;
  86        }
  87      }
  88      $rows[] = array(array(
  89        'data' => $element['#empty'],
  90        'colspan' => $header_count,
  91        'class' => 'empty message',
  92      ));
  93    }
  94  
  95    return theme('table', $header, $rows, $element['#attributes']);
  96  }
  97  
  98  /**
  99   * Wrapper for theming a form element to add field prefix and suffix support.
 100   */
 101  function _elements_theme_form_element_wrapper($element, $output) {
 102    if (isset($element['#field_prefix'])) {
 103      $output = '<span class="field-prefix">' . $element['#field_prefix'] . '</span> ' . $output;
 104    }
 105  
 106    if (isset($element['#field_suffix'])) {
 107      $output .= ' <span class="field-suffix">' . $element['#field_suffix'] . '</span>';
 108    }
 109  
 110    return theme('form_element', $element, $output);
 111  }
 112  
 113  /**
 114   * Returns HTML for an emailfield form element.
 115   *
 116   * @param $element
 117   *   An associative array containing the properties of the element.
 118   *   Properties used: #title, #value, #description, #size, #maxlength,
 119   *   #required, #placeholder, #attributes, #autocomplete_path.
 120   *
 121   * @ingroup themeable
 122   */
 123  function theme_emailfield($element) {
 124    $element['#attributes']['type'] = 'email';
 125    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
 126    _form_set_class($element, array('form-text', 'form-email'));
 127  
 128    $extra = elements_add_autocomplete($element);
 129    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 130  
 131    $output = _elements_theme_form_element_wrapper($element, $output . $extra);
 132    return $output;
 133  }
 134  
 135  /**
 136   * Returns HTML for a searchfield form element.
 137   *
 138   * @param $element
 139   *   An associative array containing the properties of the element.
 140   *   Properties used: #title, #value, #description, #size, #maxlength,
 141   *   #required, #placeholder, #attributes, #autocomplete_path.
 142   *
 143   * @ingroup themeable
 144   */
 145  function theme_searchfield($element) {
 146    $element['#attributes']['type'] = 'search';
 147    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
 148    _form_set_class($element, array('form-text', 'form-search'));
 149  
 150    $extra = elements_add_autocomplete($element);
 151    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 152  
 153    $output = _elements_theme_form_element_wrapper($element, $output . $extra);
 154    return $output;
 155  }
 156  
 157  /**
 158   * Returns HTML for a telfield form element.
 159   *
 160   * @param $element
 161   *   An associative array containing the properties of the element.
 162   *   Properties used: #title, #value, #description, #size, #maxlength,
 163   *   #required, #placeholder, #attributes.
 164   *
 165   * @ingroup themeable
 166   */
 167  function theme_telfield($element) {
 168    $element['#attributes']['type'] = 'tel';
 169    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
 170    _form_set_class($element, array('form-text', 'form-tel'));
 171  
 172    $extra = elements_add_autocomplete($element);
 173    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 174  
 175    $output = _elements_theme_form_element_wrapper($element, $output . $extra);
 176    return $output;
 177  }
 178  
 179  /**
 180   * Returns HTML for an urlfield form element.
 181   *
 182   * @param $element
 183   *   An associative array containing the properties of the element.
 184   *   Properties used: #title, #value, #description, #size, #maxlength,
 185   *   #required, #placeholder, #attributes, #autocomplete_path.
 186   *
 187   * @ingroup themeable
 188   */
 189  function theme_urlfield($element) {
 190    $element['#attributes']['type'] = 'url';
 191    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder'));
 192    _form_set_class($element, array('form-text', 'form-url'));
 193  
 194    $extra = elements_add_autocomplete($element);
 195    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 196  
 197    $output = _elements_theme_form_element_wrapper($element, $output . $extra);
 198    return $output;
 199  }
 200  
 201  /**
 202   * Returns HTML for a numberfield form element.
 203   *
 204   * @param $element
 205   *   An associative array containing the properties of the element.
 206   *   Properties used: #title, #value, #description, #size, #maxlength,
 207   *   #placeholder, #min, #max, #step, #required, #attributes.
 208   *
 209   * @ingroup themeable
 210   */
 211  function theme_numberfield($element) {
 212    $element['#attributes']['type'] = 'number';
 213    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder', 'min', 'max', 'step'));
 214    _form_set_class($element, array('form-text', 'form-number'));
 215  
 216    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 217  
 218    $output = _elements_theme_form_element_wrapper($element, $output);
 219    return $output;
 220  }
 221  
 222  /**
 223   * Returns HTML for a rangefield form element.
 224   *
 225   * @param $element
 226   *   An associative array containing the properties of the element.
 227   *   Properties used: #title, #value, #description, #size, #maxlength,
 228   *   #placeholder, #min, #max, #step, #required, #attributes.
 229   *
 230   * @ingroup themeable
 231   */
 232  function theme_rangefield($element) {
 233    $element['#attributes']['type'] = 'range';
 234    element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength', 'placeholder', 'min', 'max', 'step'));
 235    _form_set_class($element, array('form-text', 'form-range'));
 236  
 237    $output = '<input' . drupal_attributes($element['#attributes']) . ' />';
 238  
 239    $output = _elements_theme_form_element_wrapper($element, $output);
 240    return $output;
 241  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7