You are here

ds_test.module in Display Suite 7

Same filename and directory in other branches
  1. 7.2 tests/ds_test.module

Display Suite test module.

File

tests/ds_test.module
View source
<?php

/**
 * @file
 * Display Suite test module.
 */

/**
 * Implements hook_install().
 */
function ds_test_install() {
  variable_set('ds_extras_region_to_block', TRUE);
  variable_set('ds_extras_switch_view_mode', TRUE);
  variable_set('ds_extras_hide_page_title', TRUE);
  variable_set('ds_extras_field_template', TRUE);
  variable_set('ds_extras_revision_view_mode', TRUE);
  variable_set('ds_extras_fields_extra', TRUE);
  variable_set('ds_extras_fields_extra_list', "node|article|ds_extras_extra_test_field\nnode|article|ds_extras_second_field");
  variable_set('ds_extras_vd', TRUE);
}

/**
 * Implements hook_views_api().
 */
function ds_test_views_api($module, $api) {
  if ($module == 'views' && $api == 'views_default') {
    return array(
      'version' => 3,
    );
  }
}

/**
 * Helper function to return the tag name basid on tid.
 */
function ds_test_get_tag_name($raw_value, $object) {
  $term = taxonomy_term_load($raw_value);
  return $term->name;
}

/**
 * Helper function to return advanced view mode.
 */
function ds_views_row_adv_ds_testing($entity, $view_mode, $load_comments) {
  return 'Advanced display for id ' . $entity->nid;
}

/**
 * Implements hook_field_extra_fields().
 */
function ds_test_field_extra_fields() {
  $extra = array();

  // Register a single field to test that
  // extra fields in the hidden region are really hidden.
  $extra['node']['article']['display']['heavy_field'] = array(
    'label' => t('Heavy extra test field'),
    'weight' => 10,
  );
  return $extra;
}

/**
 * Implements hook_node_view().
 */
function ds_test_node_view($node, $view_mode, $langcode) {
  $node->content['ds_extras_extra_test_field'] = array(
    '#markup' => 'This is an extra field made available through "Extra fields" functionality.',
    '#weight' => 10,
  );

  // Check whether the heavy extra field is rendered or not.
  if ($node->type == 'article') {
    $fields = field_extra_fields_get_display('node', 'article', $view_mode);
    if (isset($fields['heavy_field']) && $fields['heavy_field']['visible']) {
      $node->content['heavy_field'] = array(
        '#markup' => 'Heavy field',
        '#weight' => $fields['heavy_field']['weight'],
      );
    }
  }
}

/**
 * Implements hook_ctools_plugin_directory().
 */
function ds_test_ctools_plugin_directory($module, $plugin) {

  // Safety: go away if CTools is not at an appropriate version.
  if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
    return;
  }
  if ($module == 'panels') {
    return 'plugins/' . $plugin;
  }
}

/**
 * Implements hook_ds_layout_info_alter().
 */
function ds_test_ds_layout_info_alter(&$layouts) {
  unset($layouts['ds_3col_stacked_equal_width']);
}

/**
 * Implements hook_ds_fields_info().
 */
function ds_test_ds_fields_info($entity_type) {
  if ($entity_type == 'node') {
    $fields['node']['ds_test_field'] = array(
      'title' => t('Test code field from hook'),
      'field_type' => DS_FIELD_TYPE_FUNCTION,
      'function' => 'dstest_render_test_field',
    );
    $fields['node']['ds_test_field_2'] = array(
      'title' => t('Test code field from hook 2'),
      'field_type' => DS_FIELD_TYPE_FUNCTION,
      'function' => 'dstest_render_test_field',
    );
    return $fields;
  }
}

/**
 * Implements hook_ds_field_theme_functions_info().
 */
function ds_test_ds_field_theme_functions_info() {
  return array(
    'ds_test_theming_function' => t('Field test function'),
  );
}

/**
 * Theme field test function.
 */
function ds_test_theming_function($variables) {
  return 'Testing field output through custom function';
}

/**
 * Render the test code field.
 */
function dstest_render_test_field($field) {
  return 'Test code field on node ' . $field['entity']->nid;
}

/**
 * Implements hook_ds_fields_info_alter().
 */
function ds_test_ds_fields_info_alter(&$fields, $entity_type) {
  if (isset($fields['ds_test_field_2'])) {
    $fields['ds_test_field_2']['title'] = 'Field altered';
  }
}

/**
 * Implements hook_ds_layouts_info().
 */
function ds_test_ds_layout_info() {
  $path = drupal_get_path('module', 'ds_test');
  $layouts = array(
    'dstest_1col' => array(
      'label' => t('Test One column'),
      'path' => $path . '/dstest_1col',
      'regions' => array(
        'ds_content' => t('Content'),
      ),
    ),
    'dstest_2col' => array(
      'label' => t('Test Two column'),
      'path' => $path . '/dstest_2col',
      'regions' => array(
        'left' => t('Left'),
        'right' => t('Right'),
      ),
      'css' => TRUE,
    ),
  );
  return $layouts;
}

/**
 * Implements hook_ctools_plugin_api().
 */
function ds_test_ctools_plugin_api($module, $api) {
  if ($module == 'rel' && $api == 'rel') {
    return array(
      'version' => 1,
    );
  }
}

/**
 * Implements hook_rel_build_info().
 */
function ds_test_rel_build_info() {
  $builds = array();
  $build_id = 'ds_edit_view_mode_form';
  $rel_build = new stdClass();
  $rel_build->build_id = $build_id;
  $rel_build->api_version = 1;
  $rel_build->label = 'View mode';
  $rel_build->entity_type = 'rel_build';
  $rel_build->bundle = $build_id;
  $rel_build->view_mode = 'form';
  $rel_build->context = 'form';
  $rel_build->path = 'admin/structure/rel/manage/' . $build_id;
  $rel_build->elements = array(
    'name' => array(
      'owner' => 'rel',
      'label' => t('Label'),
      'weight' => 1,
    ),
    'view_mode' => array(
      'owner' => 'rel',
      'label' => t('Machine name'),
      'weight' => 2,
    ),
    'entities' => array(
      'owner' => 'rel',
      'label' => t('Entities'),
      'weight' => 3,
    ),
    'submit' => array(
      'owner' => 'rel',
      'label' => t('Submit'),
      'weight' => 4,
    ),
  );
  $rel_build->duplicate = array();
  $builds[$build_id] = $rel_build;
  return $builds;
}

Functions