You are here

function date_repeat_form_element_radios_process in Date 8

Same name and namespace in other branches
  1. 7.3 date_repeat/date_repeat.module \date_repeat_form_element_radios_process()
  2. 7.2 date_repeat/date_repeat.module \date_repeat_form_element_radios_process()

Process function for 'date_repeat_form_element_radios'.

1 string reference to 'date_repeat_form_element_radios_process'
date_repeat_element_info in date_repeat/date_repeat.module
Implements hook_element_info().

File

date_repeat/date_repeat.module, line 314
This module creates a form element that allows users to select repeat rules for a date, and reworks the result into an iCal RRULE string that can be stored in the database.

Code

function date_repeat_form_element_radios_process($element) {
  $childrenkeys = element_children($element);
  if (count($element['#options']) && count($element['#options']) == count($childrenkeys)) {
    $weight = 0;
    $children = array();
    $classes = isset($element['#div_classes']) ? $element['#div_classes'] : array();
    foreach ($childrenkeys as $childkey) {
      $children[$childkey] = $element[$childkey];
      unset($element[$childkey]);
    }
    foreach ($element['#options'] as $key => $choice) {
      $currentchildkey = array_shift($childrenkeys);
      $weight += 0.001;
      $class = array_shift($classes);
      $element += array(
        $key => array(),
      );
      $parents_for_id = array_merge($element['#parents'], array(
        $key,
      ));
      $element[$key] += array(
        '#prefix' => '<div' . ($class ? " class=\"{$class}\"" : '') . '>',
        '#type' => 'radio',
        '#title' => $choice,
        '#title_display' => 'invisible',
        '#return_value' => $key,
        '#default_value' => isset($element['#default_value']) ? $element['#default_value'] : NULL,
        '#attributes' => $element['#attributes'],
        '#parents' => $element['#parents'],
        '#id' => drupal_html_id('edit-' . implode('-', $parents_for_id)),
        '#ajax' => isset($element['#ajax']) ? $element['ajax'] : NULL,
        '#weight' => $weight,
        '#theme_wrappers' => array(),
        '#suffix' => ' ',
      );
      $child = $children[$currentchildkey];
      $weight += 0.001;
      $child['#weight'] = $weight;
      $child['#title_display'] = 'invisible';
      $child['#suffix'] = (!empty($child['#suffix']) ? $child['#suffix'] : '') . '</div>';
      $child['#parents'] = $element['#parents'];
      array_pop($child['#parents']);
      array_push($child['#parents'], $currentchildkey);
      $element_prototype = element_info($child['#type']);
      $old_wrappers = array();
      if (isset($child['#theme_wrappers'])) {
        $old_wrappers += $child['#theme_wrappers'];
      }
      if (isset($element_prototype['#theme_wrappers'])) {
        $old_wrappers += $element_prototype['#theme_wrappers'];
      }
      $child['#theme_wrappers'] = array();
      foreach ($old_wrappers as $wrapper) {
        if ($wrapper != 'form_element') {
          $child['#theme_wrappers'][] = $wrapper;
        }
      }
      $element[$currentchildkey] = $child;
    }
  }
  return $element;
}