You are here

function phone_field_settings in Phone 6

Same name and namespace in other branches
  1. 5 phone.module \phone_field_settings()

Implementation of hook_field_settings().

Handle the settings for a field.

Parameters

$op: The operation to be performed. Possible values:

  • "form": Display the field settings form.
  • "validate": Check the field settings form for errors.
  • "save": Declare which fields to save back to the database.
  • "database columns": Declare the columns that content.module should create and manage on behalf of the field. If the field module wishes to handle its own database storage, this should be omitted.
  • "filters": Declare the Views filters available for the field. (this is used in CCK's default Views tables definition) They always apply to the first column listed in the "database columns" array.

$field: The field on which the operation is to be performed.

Return value

This varies depending on the operation.

  • "form": an array of form elements to add to the settings page.
  • "validate": no return value. Use form_set_error().
  • "save": an array of names of form elements to be saved in the database.
  • "database columns": an array keyed by column name, with arrays of column information as values. This column information must include "type", the MySQL data type of the column, and may also include a "sortable" parameter to indicate to views.module that the column contains ordered information. TODO: Details of other information that can be passed to the database layer can be found in the API for the Schema API.
  • "filters": an array of 'filters' definitions as expected by views.module (see Views Documentation). When providing several filters, it is recommended to use the 'name' attribute in order to let the user distinguish between them. If no 'name' is specified for a filter, the key of the filter will be used instead.

File

./phone.module, line 117
Defines phone number fields for CCK. Provide some verifications on the phone numbers

Code

function phone_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['phone_country_code'] = array(
        '#type' => 'checkbox',
        '#title' => t('Add the country code if not filled by the user'),
        '#default_value' => isset($field['phone_country_code']) ? $field['phone_country_code'] : '',
      );
      if ($field['type'] == 'int_phone') {
        $form['phone_int_help'] = array(
          '#type' => 'markup',
          '#value' => t('International phone numbers are in the form +XX YYYYYYY where XX is a country code and YYYYYYY is the local number. This field type is based off of the <a href="http://www.itu.int/rec/T-REC-E.123/en">E.123 specification</a>.'),
        );
        $form['phone_default_country_code'] = array(
          '#type' => 'textfield',
          '#title' => t('Default country code to add to international numbers without one (omit + sign)'),
          '#default_value' => isset($field['phone_default_country_code']) ? $field['phone_default_country_code'] : '1',
        );
        $form['phone_int_max_length'] = array(
          '#type' => 'textfield',
          '#title' => t('Maximum length of international numbers, according to the ITU this is 15'),
          '#default_value' => isset($field['phone_int_max_length']) ? $field['phone_int_max_length'] : '15',
        );
      }
      if ($field['type'] == 'ca_phone') {
        $form['ca_phone_separator'] = array(
          '#type' => 'textfield',
          '#title' => t('Separator'),
          '#default_value' => isset($field['ca_phone_separator']) ? $field['ca_phone_separator'] : '-',
          '#size' => 2,
        );
        $form['ca_phone_parentheses'] = array(
          '#type' => 'checkbox',
          '#title' => t('Use parentheses around area code'),
          '#default_value' => isset($field['ca_phone_parentheses']) ? $field['ca_phone_parentheses'] : 1,
        );
      }
      return $form;
    case 'save':
      $settings = array(
        'phone_country_code',
      );
      if ($field['type'] == 'ca_phone') {
        array_push($settings, 'ca_phone_separator', 'ca_phone_parentheses');
      }
      if ($field['type'] == 'int_phone') {
        array_push($settings, 'phone_int_help', 'phone_default_country_code', 'phone_int_max_length');
      }
      return $settings;
    case 'database columns':
      if ($field['type'] == 'fr_phone' || $field['type'] == 'be_phone' || $field['type'] == 'it_phone' || $field['type'] == 'el_phone' || $field['type'] == 'ch_phone' || $field['type'] == 'ca_phone' || $field['type'] == 'cr_phone' || $field['type'] == 'pa_phone' || $field['type'] == 'pa_phone' || $field['type'] == 'gb_phone' || $field['type'] == 'ru_phone' || $field['type'] == 'ua_phone' || $field['type'] == 'es_phone' || $field['type'] == 'au_phone' || $field['type'] == 'cs_phone' || $field['type'] == 'hu_phone' || $field['type'] == 'pl_phone' || $field['type'] == 'nl_phone' || $field['type'] == 'se_phone' || $field['type'] == 'za_phone' || $field['type'] == 'il_phone' || $field['type'] == 'nz_phone' || $field['type'] == 'br_phone' || $field['type'] == 'cl_phone' || $field['type'] == 'cl_phone' || $field['type'] == 'hk_phone' || $field['type'] == 'mo_phone' || $field['type'] == 'ph_phone' || $field['type'] == 'sg_phone' || $field['type'] == 'jo_phone' || $field['type'] == 'eg_phone' || $field['type'] == 'pk_phone' || $field['type'] == 'int_phone') {
        $columns = array(
          'value' => array(
            'type' => 'varchar',
            'length' => 255,
            'not null' => FALSE,
          ),
        );
      }
      return $columns;
  }
}