You are here

function text_widget_settings in Content Construction Kit (CCK) 6

Same name in this branch
  1. 6 examples/simple_field.php \text_widget_settings()
  2. 6 examples/example_field.php \text_widget_settings()
  3. 6 modules/text/text.module \text_widget_settings()
Same name and namespace in other branches
  1. 5 text.module \text_widget_settings()
  2. 6.3 modules/text/text.module \text_widget_settings()
  3. 6.2 modules/text/text.module \text_widget_settings()

Implementation of hook_widget_settings().

Handle the parameters for a widget.

Parameters

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

  • "form": Display the widget settings form.
  • "validate": Check the widget settings form for errors.
  • "save": Declare which pieces of information to save back to the database.

$widget: The widget 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.

File

examples/example_field.php, line 540
These hooks are defined by field modules, modules that define a new kind of field for insertion in a content type.

Code

function text_widget_settings($op, $widget) {
  switch ($op) {
    case 'form':
      $form = array();
      if ($widget['type'] == 'text_textfield') {
        $form['rows'] = array(
          '#type' => 'hidden',
          '#value' => 1,
        );
      }
      else {
        $form['rows'] = array(
          '#type' => 'textfield',
          '#title' => t('Rows'),
          '#default_value' => is_numeric($widget['rows']) ? $widget['rows'] : 5,
          '#required' => TRUE,
        );
      }
      return $form;
    case 'validate':
      if (!is_numeric($widget['rows']) || intval($widget['rows']) != $widget['rows'] || $widget['rows'] <= 0) {
        form_set_error('rows', t('"Rows" must be a positive integer.'));
      }
      break;
    case 'save':
      return array(
        'rows',
      );
  }
}