You are here

function userreference_field_settings in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 5 userreference.module \userreference_field_settings()
  2. 6.3 modules/userreference/userreference.module \userreference_field_settings()
  3. 6.2 modules/userreference/userreference.module \userreference_field_settings()

Implementation of hook_field_settings().

File

modules/userreference/userreference.module, line 64
Defines a field type for referencing a user from a node.

Code

function userreference_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['referenceable_roles'] = array(
        '#type' => 'checkboxes',
        '#title' => t('User roles that can be referenced'),
        '#default_value' => is_array($field['referenceable_roles']) ? array_filter($field['referenceable_roles']) : array(),
        '#options' => user_roles(1),
      );
      $form['referenceable_status'] = array(
        '#type' => 'checkboxes',
        '#title' => t('User status that can be referenced'),
        '#default_value' => is_array($field['referenceable_status']) ? array_filter($field['referenceable_status']) : array(
          1,
        ),
        '#options' => array(
          1 => t('Active'),
          0 => t('Blocked'),
        ),
      );
      return $form;
    case 'save':
      return array(
        'referenceable_roles',
        'referenceable_status',
      );
    case 'database columns':
      $columns = array(
        'uid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => FALSE,
        ),
      );
      return $columns;
    case 'views data':
      $data = content_views_field_views_data($field);
      $db_info = content_database_info($field);
      $table_alias = content_views_tablename($field);

      // Swap the filter handler to the 'in' operator.
      $data[$table_alias][$field['field_name'] . '_uid']['filter']['handler'] = 'views_handler_filter_many_to_one_content';

      // Add a relationship for related user.
      $data[$table_alias][$field['field_name'] . '_uid']['relationship'] = array(
        'base' => 'users',
        'field' => $db_info['columns']['uid']['column'],
        'handler' => 'views_handler_relationship',
      );
      return $data;
  }
}