You are here

availability_calendar_booking_formlet.module in Availability Calendars 7.5

Availability Calendar booking formlet module. This submodule of the Availability Calendar module defines a field that shows a small booking form that interacts with a calendar field. The form only has an arrival and departure date field and a submit button that is supposed to post the values to a webform where the visitor can enter its personal details and other requested information.

@author Erwin Derksen (http://drupal.org/user/750928)

@todo:

  • allow to disable booking form on a per node basis and an instance setting to disallow this.
  • allow to override the url on a per node basis.
  • disable "Number of values" on field instance setting form.
  • check the setting interactive on calendar fields when this fields get added
  • can I reuse something from node reference or linkit module to select URL?
  • what more information to send in hidden fields? field name, delta, language
  • label and help text for departure date in full day mode is incorrect (last day of your stay, not departure date)

File

booking_formlet/availability_calendar_booking_formlet.module
View source
<?php

/**
 * @file
 * Availability Calendar booking formlet module. This submodule of the
 * Availability Calendar module defines a field that shows a small booking form
 * that interacts with a calendar field. The form only has an arrival and
 * departure date field and a submit button that is supposed to post the values
 * to a webform where the visitor can enter its personal details and other
 * requested information.
 *
 * @author Erwin Derksen (http://drupal.org/user/750928)
 *
 * @todo:
 * - allow to disable booking form on a per node basis and an instance setting
 *   to disallow this.
 * - allow to override the url on a per node basis.
 * - disable "Number of values" on field instance setting form.
 * - check the setting interactive on calendar fields when this fields get added
 * - can I reuse something from node reference or linkit module to select URL?
 * - what more information to send in hidden fields? field name, delta, language
 * - label and help text for departure date in full day mode is incorrect (last
 *   day of your stay, not departure date)
 */

/***************************************************************
 * Field Type API hooks
 ***************************************************************/

/**
 * Implements hook_field_info().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_info/7
 *
 * Provides the descriptions of the fields offered by this module.
 */
function availability_calendar_booking_formlet_field_info() {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_field_info_inc();
}

/**
 * Implements hook_field_settings_form().
 * @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/function/hook_field_settings_form/7
 */
function availability_calendar_booking_formlet_field_settings_form($field, $instance, $has_data) {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_field_settings_form_inc($field, $instance, $has_data);
}

/**
 * Implements hook_field_instance_settings_form().
 * @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/function/hook_field_instance_settings_form/7
 */
function availability_calendar_booking_formlet_field_instance_settings_form() {
  return array();
}

/**
 * Implements hook_field_is_empty().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_is_empty/7
 *
 * A booking formlet is always considered empty, it is a display only field.
 */
function availability_calendar_booking_formlet_field_is_empty() {
  return TRUE;
}

/**
 * Implements hook_field_validate().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_validate/7
 *
 * Verifies that the booking formlet is valid. The booking formlet is a display
 * only field and thus does not need to be validated.
 */
function availability_calendar_booking_formlet_field_validate() {
}

/**************************************************************************
 * Field Type API: Widget
 *
 * The widget is the form element used to receive input from the user
 * when the field is being populated.
 **************************************************************************/

/**
 * Implements hook_field_widget_info.
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_widget_info/7
 *
 * For now, this module defines 1 widget. Other widgets may be defined in the
 * future or by other modules.
 */
function availability_calendar_booking_formlet_field_widget_info() {
  return array(
    'availability_calendar_booking_formlet' => array(
      'label' => t('- None -'),
      'description' => '',
      'field types' => array(
        'availability_calendar_booking_formlet',
      ),
      'settings' => array(),
      'behaviors' => array(
        'multiple values' => FIELD_BEHAVIOR_CUSTOM,
        'default value' => FIELD_BEHAVIOR_NONE,
      ),
    ),
  );
}

/**
 * Implements hook_field_widget_settings_form
 * @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/function/hook_field_widget_settings_form/7
 */
function availability_calendar_booking_formlet_field_widget_settings_form() {
  return array();
}

/**
 * Implements hook_field_widget_form().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_widget_form/7
 */
function availability_calendar_booking_formlet_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  $element['#access'] = FALSE;
  return $element;
}

/******************************************************************************
 *  Field Type API: Formatter
 *
 *  These are the api hooks that present formatted (themed) output to the user.
 *****************************************************************************/

/**
 * Implements hook_field_formatter_info().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_formatter_info/7
 */
function availability_calendar_booking_formlet_field_formatter_info() {
  return array(
    'availability_calendar_booking_formlet' => array(
      'label' => t('Show booking formlet'),
      'field types' => array(
        'availability_calendar_booking_formlet',
      ),
      'settings' => array(
        'submit_only' => FALSE,
        'single_day_only' => FALSE,
        'display_duration' => '',
        'preset_begin_date_source' => 'none',
        'preset_begin_date_key' => '',
        'preset_end_date_source' => 'none',
        'preset_end_date_key' => '',
      ),
    ),
  );
}

/**
 * Implements hook_field_formatter_settings_form().
 * @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/function/hook_field_formatter_settings_form/7
 */
function availability_calendar_booking_formlet_field_formatter_settings_form($field, $instance, $view_mode, $form, $form_state) {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_field_formatter_settings_form_inc($field, $instance, $view_mode, $form, $form_state);
}

/**
 * Implements hook_field_formatter_settings_summary().
 * @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/function/hook_field_formatter_settings_summary/7
 */
function availability_calendar_booking_formlet_field_formatter_settings_summary($field, $instance, $view_mode) {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_field_formatter_settings_summary_inc($field, $instance, $view_mode);
}

/**
 * Implements hook_field_formatter_view().
 * @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/hook_field_formatter_view/7
 */
function availability_calendar_booking_formlet_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, &$items, $display) {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_field_formatter_view_inc($entity_type, $entity, $field, $instance, $langcode, $items, $display);
}

/**
 * Callback for drupal_get_form() to create the booking formlet view.
 *
 * drupal_get_form() is called by hook_field_formatter_view (in our
 * case: availability_calendar_booking_formlet_field_formatter_view).
 *
 * @param string $form_id
 * @param array $form_state
 *
 * @return array
 */
function availability_calendar_booking_formlet_form($form_id, $form_state) {
  module_load_include('inc', 'availability_calendar_booking_formlet');
  return availability_calendar_booking_formlet_form_inc($form_id, $form_state);
}

Functions

Namesort descending Description
availability_calendar_booking_formlet_field_formatter_info Implements hook_field_formatter_info(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_formatter_settings_form Implements hook_field_formatter_settings_form(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_booking_formlet_field_formatter_settings_summary Implements hook_field_formatter_settings_summary(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_booking_formlet_field_formatter_view Implements hook_field_formatter_view(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_info Implements hook_field_info(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_instance_settings_form Implements hook_field_instance_settings_form(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_booking_formlet_field_is_empty Implements hook_field_is_empty(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_settings_form Implements hook_field_settings_form(). @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_booking_formlet_field_validate Implements hook_field_validate(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_widget_form Implements hook_field_widget_form(). @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_widget_info Implements hook_field_widget_info. @link http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...
availability_calendar_booking_formlet_field_widget_settings_form Implements hook_field_widget_settings_form @link http://api.drupal.org/api/drupal/modules--field_ui--field_ui.api.php/fun...
availability_calendar_booking_formlet_form Callback for drupal_get_form() to create the booking formlet view.