You are here

function availability_calendar_field_widget_month_form in Availability Calendars 7.4

Same name and namespace in other branches
  1. 7.5 availability_calendar.widget.inc \availability_calendar_field_widget_month_form()
  2. 7.3 availability_calendar.widget.inc \availability_calendar_field_widget_month_form()

Defines the form elements to edit this field.

Called by our implementation of hook_field_widget_form(). Parameters are as passed to hook_field_widget_form(). Return is what hook_field_widget_form() should return.

_state

Parameters

array $form:

array $field:

array $instance:

string $langcode:

array $items:

integer $delta:

array $element:

Return value

array Form elements to edit this field on an entity edit form.

1 call to availability_calendar_field_widget_month_form()
availability_calendar_field_widget_form in ./availability_calendar.field.inc
Implements hook_field_widget_form(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

File

./availability_calendar.widget.inc, line 27

Code

function availability_calendar_field_widget_month_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  static $new_cid_count = 0;
  $item = isset($items[$delta]) ? $items[$delta] : NULL;
  $cid = !empty($item['cid']) ? $item['cid'] : 'new' . ++$new_cid_count;
  $cvid = availability_calendar_get_cvid();
  $name = !empty($item['name']) ? $item['name'] : '';
  $settings = $instance['widget']['settings'] + $instance['settings'] + $field['settings'];

  // Make sure this file gets loaded on submit
  $form_state['build_info']['files'][] = array(
    'type' => 'inc',
    'module' => 'availability_calendar',
    'name' => 'availability_calendar.widget',
  );
  $element = array_merge($element, array(
    '#type' => 'fieldset',
    '#element_validate' => array(
      'availability_calendar_field_widget_month_form_validate',
    ),
    '#attached' => availability_calendar_field_widget_month_attach_js_css($cvid),
  ));
  $element['enabled'] = array(
    '#type' => 'checkbox',
    // Don't show the checkbox if the user may not disable the calendar.
    '#access' => $settings['allow_disable'],
    '#title' => t('Enable the availability calendar'),
    '#description' => t("Uncheck the checkbox if you don't want a calendar at all for this @entity", array(
      '@entity' => $element['#entity_type'],
    )),
    '#default_value' => isset($item['enabled']) ? $item['enabled'] : 1,
    '#attributes' => array(
      'class' => array(
        'availability-enable',
      ),
    ),
  );
  $element['calendar_details_div'] = array(
    '#type' => 'markup',
    '#markup' => '<div class="availability-details">',
  );
  $element['name'] = array(
    '#type' => 'textfield',
    // Don't show this textbox if the user may not give the calendar a name.
    '#access' => $settings['add_name'],
    '#title' => t('Name'),
    '#default_value' => isset($item['name']) ? $item['name'] : '',
  );
  $element['description'] = array(
    '#type' => 'item',
    '#title' => t('Availability'),
    '#description' => t('<p>To update the calendar: select the new state and the date range to apply it to. Repeat if needed. When finished, click on <em>@button</em>. You can select a date range by clicking on either:</p>
     <ul>
     <li>The begin and end date of the period you want to change.</li>
     <li>A week number to select that whole week at once.</li>
     <li>The name of the month to select that whole month at once.</li>
     <li>The name of a day of the week to select all those days of the week in that month.</li>
     </ul>', array(
      '@button' => t('Save'),
    )),
  );
  $allowed_states = availability_calendar_get_states(array_filter($settings['allowed_states']), 'label');
  $default_state = array_key_exists($settings['default_state'], $allowed_states) ? $settings['default_state'] : key($allowed_states);
  $element['availability_states'] = array(
    '#type' => 'radios',
    '#title' => t('Select new state'),
    '#default_value' => $default_state,
    '#options' => $allowed_states,
    '#attributes' => array(
      'class' => array(
        'availability-states',
      ),
    ),
  );
  $element['availability_calendar'] = array(
    '#type' => 'markup',
    '#theme' => $instance['widget']['type'],
    '#markup' => '',
    '#cid' => $cid,
    '#cvid' => $cvid,
    '#name' => $name,
    '#settings' => $settings,
  );
  $element['calendar_details_enddiv'] = array(
    '#type' => 'markup',
    '#markup' => '</div>',
  );
  $element['availability_changes'] = array(
    '#type' => 'hidden',
    '#title' => t('Changes in availability'),
    '#default_value' => '',
    '#attributes' => array(
      'class' => array(
        'availability-changes',
      ),
    ),
  );

  // Add element cid. It does not have to be sent to the client, but is used on
  // submit. Store 0 for new calendars.
  $element['cid'] = array(
    '#type' => 'hidden',
    '#access' => FALSE,
    '#default_value' => (int) $cid,
  );

  // Add the unique cid, used to match changes, fields, and elements in the
  // processing phase.
  $element['cid_unique'] = array(
    '#type' => 'hidden',
    '#access' => FALSE,
    '#default_value' => $cid,
  );
  return $element;
}