function _options_properties

Describes the preparation steps required by each widget.

Parameters

$type: The type of widget: select, buttons, or onoff.

$multiple: TRUE if the field allows multiple values; FALSE otherwise.

$required: TRUE if a value is required for the field; FALSE otherwise.

$has_value: TRUE if a value is selected.

Return value

An array of properties for the widget.

1 call to _options_properties()
options_field_widget_form in drupal/core/modules/field/modules/options/options.module
Implements hook_field_widget_form().

File

drupal/core/modules/field/modules/options/options.module, line 598
Defines selection, check box and radio button widgets for text and numeric fields.

Code

function _options_properties($type, $multiple, $required, $has_value) {
  $base = array(
    'filter_xss' => FALSE,
    'strip_tags' => FALSE,
    'empty_option' => FALSE,
    'optgroups' => FALSE,
  );
  $properties = array();
  switch ($type) {
    case 'select':
      $properties = array(
        // Select boxes do not support any HTML tag.
        'strip_tags' => TRUE,
        'optgroups' => TRUE,
      );
      if ($multiple) {

        // Multiple select: add a 'none' option for non-required fields.
        if (!$required) {
          $properties['empty_option'] = 'option_none';
        }
      }
      else {

        // Single select: add a 'none' option for non-required fields,
        // and a 'select a value' option for required fields that do not come
        // with a value selected.
        if (!$required) {
          $properties['empty_option'] = 'option_none';
        }
        elseif (!$has_value) {
          $properties['empty_option'] = 'option_select';
        }
      }
      break;
    case 'buttons':
      $properties = array(
        'filter_xss' => TRUE,
      );

      // Add a 'none' option for non-required radio buttons.
      if (!$required && !$multiple) {
        $properties['empty_option'] = 'option_none';
      }
      break;
    case 'onoff':
      $properties = array(
        'filter_xss' => TRUE,
      );
      break;
  }
  return $properties + $base;
}