You are here

function nodereference_field_settings in Content Construction Kit (CCK) 5

Same name and namespace in other branches
  1. 6.3 modules/nodereference/nodereference.module \nodereference_field_settings()
  2. 6 modules/nodereference/nodereference.module \nodereference_field_settings()
  3. 6.2 modules/nodereference/nodereference.module \nodereference_field_settings()

Implementation of hook_field_settings().

File

./nodereference.module, line 35
Defines a field type for referencing one node from another.

Code

function nodereference_field_settings($op, $field) {
  switch ($op) {
    case 'form':
      $form = array();
      $form['referenceable_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Content types that can be referenced'),
        '#multiple' => TRUE,
        '#default_value' => isset($field['referenceable_types']) ? $field['referenceable_types'] : array(),
        '#options' => array_map('check_plain', node_get_types('names')),
      );
      if (module_exists('views')) {
        $views = array(
          '--' => '--',
        );
        $result = db_query("SELECT name FROM {view_view} ORDER BY name");
        while ($view = db_fetch_array($result)) {
          $views[t('Existing Views')][$view['name']] = $view['name'];
        }
        views_load_cache();
        $default_views = _views_get_default_views();
        foreach ($default_views as $view) {
          $views[t('Default Views')][$view->name] = $view->name;
        }
        if (count($views) > 1) {
          $form['advanced'] = array(
            '#type' => 'fieldset',
            '#title' => t('Advanced - Nodes that can be referenced (View)'),
            '#collapsible' => TRUE,
            '#collapsed' => !isset($field['advanced_view']) || $field['advanced_view'] == '--',
          );
          $form['advanced']['advanced_view'] = array(
            '#type' => 'select',
            '#title' => t('View'),
            '#options' => $views,
            '#default_value' => isset($field['advanced_view']) ? $field['advanced_view'] : '--',
            '#description' => t('Choose the "Views module" view that selects the nodes that can be referenced.<br>Note :<ul><li>This will discard the "Content types" settings above. Use the view\'s "filters" section instead.</li><li>Use the view\'s "fields" section to display additional informations about candidate nodes on node creation/edition form.</li><li>Use the view\'s "sort criteria" section to determine the order in which candidate nodes will be displayed.</li></ul>'),
          );
          $form['advanced']['advanced_view_args'] = array(
            '#type' => 'textfield',
            '#title' => t('View arguments'),
            '#default_value' => isset($field['advanced_view_args']) ? $field['advanced_view_args'] : '',
            '#required' => FALSE,
            '#description' => t('Provide a comma separated list of arguments to pass to the view.'),
          );
        }
      }
      return $form;
    case 'save':
      $settings = array(
        'referenceable_types',
      );
      if (module_exists('views')) {
        $settings[] = 'advanced_view';
        $settings[] = 'advanced_view_args';
      }
      return $settings;
    case 'database columns':
      $columns = array(
        'nid' => array(
          'type' => 'int',
          'not null' => TRUE,
          'default' => '0',
        ),
      );
      return $columns;
    case 'filters':
      return array(
        'default' => array(
          'list' => '_nodereference_filter_handler',
          'list-type' => 'list',
          'operator' => 'views_handler_operator_or',
          'value-type' => 'array',
          'extra' => array(
            'field' => $field,
          ),
        ),
      );
  }
}