-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathteaser.module
More file actions
111 lines (94 loc) · 3.51 KB
/
Copy pathteaser.module
File metadata and controls
111 lines (94 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
include_once 'teaser.features.inc';
/**
* Get a list of types declared as teasers, keyed by teaser content type name.
* @return [type] [description]
*/
function teaser_get_types() {
$teaser_types = &drupal_static(__FUNCTION__);
if (empty($teaser_types)) {
$teaser_types = module_invoke_all('teaser_types');
}
return $teaser_types;
}
/**
* Get a list of types declared as teasers
* @return [type] [description]
*/
function teaser_get_types_list() {
return array_keys(teaser_get_types());
}
/**
* Determine if a bundle is a teaser type.
*/
function teaser_is_teaser($bundle = NULL) {
return in_array($bundle, teaser_get_types_list());
}
/**
* Implements hook_node_view().
*
* Disable full page views for teaser nodes.
*/
function teaser_node_view($node, $view_mode, $langcode) {
if (in_array($node->type, teaser_get_types_list()) && $view_mode == 'full' && !user_access('create ' . $node->type . ' content')) {
drupal_not_found();
exit();
}
}
/*
* Implementation of hook_form_node_form_alter()
*/
function teaser_form_node_form_alter(&$form, $form_state) {
// Alter only edit forms of teaser type nodes
if (isset($form['#node_edit_form']) && $form['#node_edit_form'] === TRUE && teaser_is_teaser($form['#bundle'])) {
// Add an after_build function, so that we can alter i18n settings (executed in an after build)
$form['#after_build'][] = 'teaser_node_form_after_build';
}
}
/**
* After build function
*/
function teaser_node_form_after_build($form, $form_state) {
// When adding new teaser nodes, set default language to the current language
if ($form['#node_edit_form'] && teaser_is_teaser($form['type']['#value']) && !isset($form['nid']['#value'])) {
if (!empty($GLOBALS['language_url'])) {
$language_to_set = $GLOBALS['language_url']->language;
}
else {
$language_to_set = $GLOBALS['language']->language;
}
$form['language']['#default_value'] = $language_to_set;
$form['language']['#value'] = $language_to_set;
// Remove Undefined from available languages
unset($form['language']['#options'][LANGUAGE_NONE]);
}
return $form;
}
/**
* Implementation of hook_node_view_alter
*/
function teaser_node_view_alter(&$build) {
// Create preview page, showing all active and rendered view modes of teaser content types.
// Only apply on full view mode.
if (isset($build['#bundle']) && teaser_is_teaser($build['#bundle']) && ($build['#view_mode'] == 'full')) {
// Save build in temp variable
$build_tmp = $build;
// Clear build mode, so that we can rebuild it
$build = array();
// Get available view modes for this entity type bundle
$entity_info = entity_get_info($build_tmp['#entity_type']);
$view_modes = $entity_info['view modes'];
$view_mode_settings = field_view_mode_settings($build_tmp['#entity_type'], $build_tmp['#bundle']);
// Loop through the view modes
foreach ($view_modes as $view_mode_name => $view_mode_info) {
if (!empty($view_mode_settings[$view_mode_name]['custom_settings']) && $view_mode_name != 'teaser_basic') { // teaser_basic is not a stand alone view mode, so skip
$build_add = node_view($build_tmp['#node'], $view_mode_name);
$build_add['#view_mode'] = $view_mode_name;
$build_add['#prefix'] = '<div class="view-mode-list-item view-mode-list-item-' . $view_mode_name . '"><span class="title">' . $view_mode_info['label'] . '</span>';
$build_add['#suffix'] = '</div>';
// Add it to build mode array
$build[] = $build_add;
}
}
}
}