You are here

function nd_ds_fields in Node displays 6.2

Same name and namespace in other branches
  1. 6.3 nd.module \nd_ds_fields()
  2. 7 nd.module \nd_ds_fields()

Implementation of hook_ds_fields().

File

./nd.module, line 442
Node displays.

Code

function nd_ds_fields($type_name, $build_mode, $extra) {
  $fields = array(
    'title' => array(
      'title' => t('Title'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'allow_formatters' => TRUE,
      'properties' => array(
        'formatters' => array(
          'nd_title_h1_nolink' => t('H1 title'),
          'nd_title_h1_link' => t('H1 title, linked to node'),
          'nd_title_h2_nolink' => t('H2 title'),
          'nd_title_h2_link' => t('H2 title, linked to node'),
          'nd_title_h2_block_nolink' => t('H2 block title'),
          'nd_title_h2_block_link' => t('H2 block title, linked to node'),
          'nd_title_p_nolink' => t('Paragraph title'),
          'nd_title_p_link' => t('Paragraph title, linked to node'),
        ),
      ),
    ),
    'author' => array(
      'title' => t('Author'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'properties' => array(
        'formatters' => array(
          'ds_author_nolink' => t('Author'),
          'ds_author_link' => t('Author linked to profile'),
        ),
      ),
    ),
    'links' => array(
      'title' => t('Links'),
      'type' => DS_FIELD_TYPE_PREPROCESS,
      'status' => DS_FIELD_STATUS_STATIC,
    ),
    'read_more' => array(
      'title' => t('Read more'),
      'type' => DS_FIELD_TYPE_CODE,
      'status' => DS_FIELD_STATUS_DEFAULT,
      'properties' => array(
        'formatters' => array(
          'ds_eval_code' => t('Default'),
        ),
        'code' => '<?php echo l(t("Read more"), "node/$object->nid"); ?>',
      ),
    ),
  );

  // Updated and posted date formatters
  if (module_exists('date_api')) {
    $date_formats = date_get_format_types('', FALSE);
  }
  else {
    $date_formats = array(
      'small' => array(
        'title' => 'Small',
        'type' => 'small',
      ),
      'medium' => array(
        'title' => 'Medium',
        'type' => 'medium',
      ),
      'large' => array(
        'title' => 'Large',
        'type' => 'large',
      ),
    );
  }
  $date_formatters = array();
  foreach ($date_formats as $formatter) {
    $date_formatters['nd_post_date_' . $formatter['type']] = t($formatter['title']);
  }

  // Regression. People upgrading from 6.x-2.2 to 6.x-2.3 will lose
  // the post date PHP code field, we can't do that by default. The
  // update_2 will make the nd_use_date_api variable false, and
  // developers can set this variable to 1 in the variable table.
  if (variable_get('nd_use_date_api', TRUE)) {
    $fields['post_date'] = array(
      'title' => t('Post date'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'properties' => array(
        'formatters' => $date_formatters,
      ),
    );
  }
  else {
    $fields['post_date'] = array(
      'title' => t('Post date'),
      'type' => DS_FIELD_TYPE_CODE,
      'status' => DS_FIELD_STATUS_DEFAULT,
      'properties' => array(
        'formatters' => array(
          'ds_eval_code' => t('Default'),
        ),
        'code' => '<?php echo format_date($object->created, "custom", "d/m/Y"); ?>',
      ),
    );
  }
  $fields['updated_date'] = array(
    'title' => t('Last updated date'),
    'type' => DS_FIELD_TYPE_THEME,
    'status' => DS_FIELD_STATUS_STATIC,
    'properties' => array(
      'formatters' => $date_formatters,
    ),
  );

  // Check for body.
  if (isset($extra['has_body']) && $extra['has_body'] == TRUE) {
    $fields['body'] = array(
      'title' => t('Body'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'allow_formatters' => TRUE,
      'properties' => array(
        'formatters' => array(
          'nd_bodyfield' => t('Default'),
        ),
      ),
    );
  }

  // Taxonomy support.
  if (module_exists('taxonomy')) {
    $all = FALSE;

    // All vocabularies per content type.
    // We can't use taxonomy_get_vocabularies() here, see http://drupal.org/node/810352.
    $result = db_query("SELECT v.vid, v.*, n.type FROM {vocabulary} v LEFT JOIN {vocabulary_node_types} n ON v.vid = n.vid WHERE n.type = '%s' ORDER BY v.weight, v.name", $type_name);
    while ($vocabulary = db_fetch_object($result)) {
      $all = TRUE;
      $fields['terms_' . $vocabulary->vid] = array(
        'title' => t('Taxonomy: @vocab', array(
          '@vocab' => $vocabulary->name,
        )),
        'type' => DS_FIELD_TYPE_THEME,
        'status' => DS_FIELD_STATUS_STATIC,
        'properties' => array(
          'css-class' => 'field-terms field-terms-' . $vocabulary->vid,
          'formatters' => array(
            'nd_terms_per_vocabulary_space' => t('Separated by space'),
            'nd_terms_per_vocabulary_linked_space' => t('Separated by space, linked to term'),
            'nd_terms_per_vocabulary_comma' => t('Separated by comma'),
            'nd_terms_per_vocabulary_linked_comma' => t('Separated by comma, linked to term'),
            'nd_terms_per_vocabulary_list' => t('Unordered list'),
            'nd_terms_per_vocabulary_linked_list' => t('Unordered list, linked to term'),
          ),
        ),
      );
    }
    if ($all) {

      // All terms.
      $fields['terms'] = array(
        'title' => t('Taxonomy: all terms'),
        'type' => DS_FIELD_TYPE_PREPROCESS,
        'status' => DS_FIELD_STATUS_STATIC,
      );
    }
  }

  // Upload support.
  if (module_exists('upload') && $build_mode != 'teaser' && variable_get("upload_{$type_name}", 1)) {
    $fields['files'] = array(
      'title' => t('Core upload'),
      'type' => DS_FIELD_TYPE_IGNORE,
      'status' => DS_FIELD_STATUS_STATIC,
    );
  }

  // Book support.
  if (module_exists('book') && book_type_is_allowed($type_name)) {
    $fields['book_navigation'] = array(
      'title' => t('Book navigation'),
      'type' => DS_FIELD_TYPE_FUNCTION,
      'status' => DS_FIELD_STATUS_STATIC,
      'properties' => array(
        'formatters' => array(
          'nd_book_navigation' => t('Book navigation'),
        ),
      ),
    );
    $fields['book_add_new_child'] = array(
      'title' => t('Book: add new child'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'properties' => array(
        'formatters' => array(
          'nd_book_add_new_child' => t('Add new child'),
        ),
      ),
    );
    $fields['book_printer_version'] = array(
      'title' => t('Book: printer version'),
      'type' => DS_FIELD_TYPE_THEME,
      'status' => DS_FIELD_STATUS_STATIC,
      'properties' => array(
        'formatters' => array(
          'nd_book_printer_version' => t('Printer version'),
        ),
      ),
    );
  }
  return array(
    'nd' => $fields,
  );
}