You are here

function nodereferrer_field_settings in NodeReferrer 6

Same name and namespace in other branches
  1. 5 nodereferrer.module \nodereferrer_field_settings()

Implementation of hook_field_settings().

File

./nodereferrer.module, line 36
Defines a field type for backlinking referencing nodes.

Code

function nodereferrer_field_settings($op, $field) {
  switch ($op) {
    case 'views data':
      $data = content_views_field_views_data($field);
      if (is_array($data)) {
        foreach ($data as $k => $v) {
          $data[$k] = array();
        }
      }
      else {
        $data = array();
      }
      return $data;
    case 'callbacks':
      return array(
        'view' => CONTENT_CALLBACK_CUSTOM,
      );
    case 'form':
      $form = array();

      // Hide unused options
      $form['required'] = array(
        '#type' => 'hidden',
        '#value' => FALSE,
      );
      $form['multiple'] = array(
        '#type' => 'hidden',
        '#value' => 0,
      );
      $form['referrer_types'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Referring Node Types'),
        '#multiple' => TRUE,
        '#default_value' => is_array($field['referrer_types']) ? $field['referrer_types'] : array(),
        '#options' => node_get_types('names'),
      );
      $options = nodereferrer_nodereference_field_options();
      $form['referrer_fields'] = array(
        '#type' => 'checkboxes',
        '#title' => t('Referring Fields'),
        '#multiple' => TRUE,
        '#default_value' => is_array($field['referrer_fields']) ? $field['referrer_fields'] : array(),
        '#options' => $options,
      );
      if (module_exists('translation')) {
        $form['referrer_translations'] = array(
          '#type' => 'checkbox',
          '#title' => t('Show on translations'),
          '#description' => t('If this is checked, referrers will also show on translations of the referenced node'),
          '#default_value' => is_int($field['referrer_translations']) ? $field['referrer_translations'] : 0,
        );
      }
      $form['referrer_nodes_per_page'] = array(
        '#type' => 'textfield',
        '#title' => t('Referrers Per Page'),
        '#description' => t('Referring nodes to display per page. 0 for no paging.'),
        '#default_value' => !empty($field['referrer_nodes_per_page']) ? $field['referrer_nodes_per_page'] : 0,
      );
      $form['referrer_pager_element'] = array(
        '#type' => 'textfield',
        '#title' => t('Pager element'),
        '#description' => t('Use this to avoid clashes if you have several pagers on one page'),
        '#default_value' => !empty($field['referrer_pager_element']) ? $field['referrer_pager_element'] : 0,
      );
      $form['referrer_order'] = array(
        '#type' => 'select',
        '#title' => t('Refferer Sort Order'),
        '#options' => array(
          'CREATED_ASC' => t('Chronological Order'),
          'CREATED_DESC' => t('Reverse Chronological Order'),
          'TITLE_ASC' => t('Title Order'),
          'TITLE_DESC' => t('Reverse Title Order'),
        ),
        '#default_value' => strlen($field['referrer_order']) ? $field['referrer_order'] : 'TITLE_ASC',
      );
      return $form;
    case 'save':
      $settings = array(
        'referrer_types',
        'referrer_fields',
        'referrer_nodes_per_page',
        'referrer_pager_element',
        'referrer_order',
      );
      if (module_exists('translation')) {
        $settings[] = 'referrer_translations';
      }
      return $settings;
  }
}