You are here

function select_or_other_widget_settings in Select (or other) 6

Same name and namespace in other branches
  1. 6.2 select_or_other.module \select_or_other_widget_settings()

Implementation of hook_widget_settings().

This is a CCK hook.

File

./select_or_other.module, line 430
The Select (or other) module.

Code

function select_or_other_widget_settings($op, $widget) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['available_options'] = array(
        '#type' => 'textarea',
        '#title' => t('Available options'),
        '#description' => t('A list of values that are, by default, available for selection. Enter one value per line, in the format key|label. The key is the value that will be stored in the database, and the label is what will be displayed to the user.  This is not the same as <em>allowed values</em> (below) which will also restrict what a user can type into the <em>other</em> textfield.'),
        '#default_value' => isset($widget['available_options']) ? $widget['available_options'] : '',
      );
      $form['available_options_fieldset']['advanced_options'] = array(
        '#type' => 'fieldset',
        '#title' => t('PHP code'),
        '#collapsible' => TRUE,
        '#collapsed' => empty($widget['available_options_php']),
      );
      if (user_access('Use PHP input for field settings (dangerous - grant with care)')) {
        $form['available_options_fieldset']['advanced_options']['available_options_php'] = array(
          '#type' => 'textarea',
          '#title' => t('Code'),
          '#default_value' => !empty($widget['available_options_php']) ? $widget['available_options_php'] : '',
          '#rows' => 6,
          '#description' => t('Advanced usage only: PHP code that returns a keyed array of available options. Should not include &lt;?php ?&gt; delimiters. If this field is filled out, the array returned by this code will override the available options list above.'),
        );
      }
      else {
        $form['available_options_fieldset']['advanced_options']['markup_available_options_php'] = array(
          '#type' => 'item',
          '#title' => t('Code'),
          '#value' => !empty($widget['available_options_php']) ? '<code>' . check_plain($widget['available_options_php']) . '</code>' : t('&lt;none&gt;'),
          '#description' => empty($widget['available_options_php']) ? t("You're not allowed to input PHP code.") : t('This PHP code was set by an administrator and will override the allowed values list above.'),
        );
      }
      $form['other'] = array(
        '#type' => 'textfield',
        '#title' => t('<em>Other</em> option'),
        '#description' => t('Label for the option that the user will choose when they want to supply an <em>other</em> value.'),
        '#default_value' => isset($widget['other']) ? $widget['other'] : t('Other'),
        '#required' => TRUE,
      );
      $form['other_unknown_defaults'] = array(
        '#type' => 'select',
        '#title' => t('<em>Other</em> value as default value'),
        '#description' => t("If any incoming default values do not appear in <em>available options</em> (i.e. set as <em>other</em> values), what should happen?"),
        '#options' => array(
          'other' => t('Add the values to the other textfield.'),
          'append' => t('Append the values to the options'),
          'ignore' => t('Ignore the values'),
        ),
        '#default_value' => isset($widget['other_unknown_defaults']) ? $widget['other_unknown_defaults'] : 'other',
        '#required' => TRUE,
      );

      /*
      There are design issues with saving multiple other values with some CCK widgets - this needs a rethink.

      $form['other_delimiter'] = array(
        '#type' => 'textfield',
        '#title' => t('Other delimiter'),
        '#description' => t("Delimiter string to delimit multiple 'other' values into the <em>other</em> textfield.  If you enter <em>FALSE</em> only the last value will be used."),
        '#default_value' => isset($widget['other_delimiter']) ? $widget['other_delimiter'] : ', ',
        '#required' => TRUE,
        '#size' => 5,
      );
      */
      return $form;
    case 'save':
      return array(
        'available_options',
        'available_options_php',
        'other',
        'other_unknown_defaults',
      );
  }
}