| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <?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_fields_extra', TRUE);
- variable_set('ds_extras_hide_page_sidebars', 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);
- db_update('system')
- ->fields(array('weight' => 2))
- ->condition('name', 'ds_test')
- ->execute();
- }
- /**
- * Implements hook_theme_registry_alter().
- */
- function ds_test_theme_registry_alter(&$theme_registry) {
- // Inject ds_entity_variables in all entity theming functions.
- $entity_info = entity_get_info();
- foreach ($entity_info as $entity => $info) {
- if (isset($entity_info[$entity]['fieldable']) && $entity_info[$entity]['fieldable']) {
- // User uses user_profile for theming.
- if ($entity == 'user') $entity = 'user_profile';
- // Only add preprocess functions if entity exposes theme function.
- if (isset($theme_registry[$entity])) {
- $theme_registry[$entity]['preprocess functions'][] = 'ds_test_entity_variables';
- }
- }
- }
- // Support for File Entity.
- if (isset($theme_registry['file_entity'])) {
- $theme_registry['file_entity']['preprocess functions'][] = 'ds_test_entity_variables';
- }
- // Support for Entity API.
- if (isset($theme_registry['entity'])) {
- $theme_registry['entity']['preprocess functions'][] = 'ds_test_entity_variables';
- }
- }
- /**
- * Theming function, added after ds_entity_variables().
- *
- * @param $variables
- */
- function ds_test_entity_variables(&$variables) {
- if (isset($_GET['store'])) {
- cache_set('ds_test', $variables);
- }
- }
- /**
- * 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_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',
- );
- $fields['node']['ds_test_field_empty_string'] = array(
- 'title' => t('Test code field that returns an empty string'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_empty_string',
- );
- $fields['node']['ds_test_field_false'] = array(
- 'title' => t('Test code field that returns FALSE'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_false',
- );
- $fields['node']['ds_test_field_null'] = array(
- 'title' => t('Test code field that returns NULL'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_null',
- );
- $fields['node']['ds_test_field_nothing'] = array(
- 'title' => t('Test code field that returns nothing'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_nothing',
- );
- $fields['node']['ds_test_field_zero_int'] = array(
- 'title' => t('Test code field that returns zero as an integer'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_zero_int',
- );
- $fields['node']['ds_test_field_zero_string'] = array(
- 'title' => t('Test code field that returns zero as a string'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_zero_string',
- );
- $fields['node']['ds_test_field_zero_float'] = array(
- 'title' => t('Test code field that returns zero as a floating point number'),
- 'field_type' => DS_FIELD_TYPE_FUNCTION,
- 'function' => 'dstest_render_zero_float',
- );
- 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;
- }
- /**
- * Test code field that returns an empty string.
- */
- function dstest_render_empty_string() {
- return '';
- }
- /**
- * Test code field that returns FALSE.
- */
- function dstest_render_false() {
- return FALSE;
- }
- /**
- * Test code field that returns NULL.
- */
- function dstest_render_null() {
- return NULL;
- }
- /**
- * Test code field that returns nothing.
- */
- function dstest_render_nothing() {
- return;
- }
- /**
- * Test code field that returns zero as an integer.
- */
- function dstest_render_zero_int() {
- return 0;
- }
- /**
- * Test code field that returns zero as a string.
- */
- function dstest_render_zero_string() {
- return '0';
- }
- /**
- * Test code field that returns zero as a floating point number.
- */
- function dstest_render_zero_float() {
- return 0.0;
- }
- /**
- * 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_form_FORM_ID_alter().
- */
- function ds_test_form_field_ui_display_overview_form_alter(&$form, &$form_state) {
- foreach (element_children($form['fields']) as $key) {
- if (isset($form['fields'][$key]['settings_edit'])) {
- $settings = $form['fields'][$key]['settings_edit'];
- if (!empty($settings)) {
- $form['fields'][$key]['settings_edit']['#type'] = 'submit';
- $form['fields'][$key]['settings_edit']['#value'] = 'edit ' . $key;
- }
- }
- }
- }
- /**
- * Implements hook_ds_pre_render_alter().
- */
- function ds_test_ds_pre_render_alter(&$layout_render_array, $context) {
- $entity = $context['entity'];
- if (isset($entity->title) && $entity->title === 'Alter me!') {
- $layout_render_array['left'][] = array('#markup' => 'cool!', '#weight' => 20);
- }
- }
|