You are here

function hook_field_settings in Content Construction Kit (CCK) 5

Handle the parameters 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.
  • "callbacks": Describe the field's behaviour regarding hook_field operations.
  • "tables" : Declare the Views tables informations for the field. Use this operator only if you need to override CCK's default general-purpose implementation. In this case, it is probably a good idea to use the default definitions returned by content_views_field_tables($field) as a start point for your own definitions.
  • "arguments" : Declare the Views arguments informations for the field. Use this operator only if you need to override CCK's default general-purpose implementation. In this case, it is probably a good idea to use the default definitions returned by content_views_field_arguments($field) as a start point for your own definitions.
  • "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. Details of other information that can be passed to the database layer can be found at content_db_add_column().
  • "callbacks": an array describing the field's behaviour regarding hook_field operations. The array is keyed by hook_field operations ('view', 'validate'...) and has the following possible values : CONTENT_CALLBACK_NONE : do nothing for this operation CONTENT_CALLBACK_CUSTOM : use the behaviour in hook_field(operation) CONTENT_CALLBACK_DEFAULT : use content.module's default bahaviour Note : currently only the 'view' operation implements this feature. All other field operation implemented by the module _will_ be executed no matter what.
  • "tables": an array of 'tables' definitions as expected by views.module (see Views Documentation).
  • "arguments": an array of 'arguments' definitions as expected by views.module (see Views Documentation).
  • "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.
4 functions implement hook_field_settings()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

nodereference_field_settings in ./nodereference.module
Implementation of hook_field_settings().
number_field_settings in ./number.module
Implementation of hook_field_settings().
text_field_settings in ./text.module
Implementation of hook_field_settings().
userreference_field_settings in ./userreference.module
Implementation of hook_field_settings().
11 invocations of hook_field_settings()
content_database_info in ./content.module
Retrieve the database storage location(s) for a field.
content_field_instance_delete in ./content_crud.inc
Delete an existing field instance.
content_update_5 in ./content.install
Move data from per-field storage to per-content-type storage where possible.
content_views_arguments in ./content_views.inc
Implementation of hook_views_arguments().
content_views_field_tables in ./content_views.inc

... See full list

File

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

Code

function hook_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['max_length'] = array(
        '#type' => 'textfield',
        '#title' => t('Maximum length'),
        '#default_value' => $field['max_length'] ? $field['max_length'] : '',
        '#required' => FALSE,
        '#description' => t('The maximum length of the field in characters. Leave blank for an unlimited size.'),
      );
      return $form;
    case 'save':
      return array(
        'text_processing',
        'max_length',
        'allowed_values',
      );
    case 'database columns':
      $columns = array(
        'value' => array(
          'type' => 'varchar',
          'not null' => TRUE,
          'default' => "''",
          'sortable' => TRUE,
        ),
        'format' => array(
          'type' => 'int',
          'length' => 10,
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
      );
      if ($field['max_length'] == 0 || $field['max_length'] > 255) {
        $columns['value']['type'] = 'longtext';
      }
      else {
        $columns['value']['length'] = $field['max_length'];
      }
      return $columns;
    case 'callbacks':
      return array(
        'view' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'tables':
      $tables = content_views_field_tables($field);

      // whatever additions / modifications needed on the default definitions
      return $tables;
    case 'arguments':
      $arguments = content_views_field_arguments($field);

      // whatever additions / modifications needed on the default definitions
      return $arguments;
    case 'filters':
      return array(
        'substring' => array(
          'operator' => 'views_handler_operator_like',
          'handler' => 'views_handler_filter_like',
        ),
        'alpha_order' => array(
          'name' => 'alphabetical order',
          'operator' => 'views_handler_operator_gtlt',
        ),
      );
  }
}