You are here

function office_hours_field_process in Office Hours 6.2

Same name and namespace in other branches
  1. 6 office_hours.elements.inc \office_hours_field_process()

Process an individual element.

Build the form element. When creating a form using FAPI #process, note that $element['#value'] is already set. The $fields array is in $form['#field_info'][$element['#field_name']].

1 string reference to 'office_hours_field_process'
_office_hours_elements in ./office_hours.elements.inc
Implementation of hook_elements().

File

./office_hours.elements.inc, line 38
office_hours.elements.inc Office hours form elements and their theming and validation. This file is only included during the edit process to reduce memory usage.

Code

function office_hours_field_process($element, $edit, $form_state, $form) {
  drupal_add_js(drupal_get_path('module', 'office_hours') . "/office_hours.js");
  $day = $element['#weight'];
  $field = $form['#field_info'][$element['#field_name']];
  $day = $day == 0 ? 0 : ($day & 1 ? ($day - 1) / 2 : $day / 2);
  $field_day = $element['#columns'][0];
  $field_strhrs = $element['#columns'][1];
  $field_endhrs = $element['#columns'][2];
  $days = date_week_days_untranslated();
  if (!($element['#weight'] & 1)) {

    //first cell
    $element['#prefix'] = '<div class="office-hours-block">' . t($days[$day]);
  }
  elseif ($field['addhrs']) {

    // second cell, we're supposed to show the 'add hours link'
    $link = l(t('Add more hours'), 'office-hours-add', array(
      'attributes' => array(
        'class' => 'oh-add-more-link',
      ),
    )) . '<div class="office-hours-block">' . t('And from');
    $element['#prefix'] = isset($element['#value'][$field_strhrs]) ? '<div class="office-hours-block">' . t('And from') : $link;
  }
  else {

    //this is the second cell and were not showing it- better clear it (in case a value was entered before).
    $element['#prefix'] = "<div class='oh-hide'>";
    $element['#value'][$field_strhrs] = '';
  }
  $element['#suffix'] = '</div>';
  $element[$field_day] = array(
    '#type' => 'value',
    '#value' => $day,
  );
  $element[$field_strhrs] = array(
    '#type' => 'office_hours_select',
    '#title' => t('From'),
    '#default_hours' => isset($element['#value'][$field_strhrs]) ? $element['#value'][$field_strhrs] : '',
    '#granularity' => $field['granularity'],
    '#hoursformat' => $field['hoursformat'],
  );
  $element[$field_endhrs] = array(
    '#type' => 'office_hours_select',
    '#title' => t('Until'),
    '#default_hours' => isset($element['#value'][$field_endhrs]) ? $element['#value'][$field_endhrs] : '',
    '#granularity' => $field['granularity'],
    '#hoursformat' => $field['hoursformat'],
  );
  $form_state['#field_info'][$field['field_name']] = $field;
  return $element;
}