-
Notifications
You must be signed in to change notification settings - Fork 0
/
os_base.module
178 lines (165 loc) · 5.15 KB
/
os_base.module
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/**
* @file
* OpenSourcery base feature and enhancements.
*/
include_once 'os_base.features.inc';
/**
* Implements hook_admin_paths().
*/
function os_base_admin_paths() {
return array(
'node/*/add-sub-page' => TRUE,
);
}
/**
* Implements hook_menu_alter().
*
* Removes /node, as it might display the "Welcome to your new Drupal website!"
* message, or a messy, unstyled node listing and denies non-administrators
* access to field-collection view pages.
*/
function os_base_menu_alter(&$items) {
unset($items['node']);
// Turn off access to field-collection pages except for administrators.
foreach (field_info_fields() as $field) {
if ($field['type'] == 'field_collection') {
$path = field_collection_field_get_path($field);
$items[$path . '/%field_collection_item']['access callback'] = 'user_access';
$items[$path . '/%field_collection_item']['access arguments'] = array('administer fieldgroups');
}
}
}
/**
* Implements hook_form_alter().
*
* - Sets the revisions as enabled for new content types.
*/
function os_base_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'node_type_form':
if (!isset($form['#node_type']->orig_type)) {
$options = array();
// Set to published by default.
$options[] = 'status';
// Enable revisions by default.
$options[] = 'revision';
$form['workflow']['node_options']['#default_value'] = $options;
}
break;
}
// Add a variable to display revision information on node edit.
if (variable_get('os_base_force_node_revisioning', TRUE)) {
if (isset($form['type']['#value']) && $form_id == $form['type']['#value'] . '_node_form' && isset($form['revision_information'])) {
// Hide the revision log input.
$form['revision_information']['#access'] = FALSE;
}
}
}
/**
* Implements hook_date_format_types().
*/
function os_base_date_format_types() {
return array(
'day' => t('Day'),
'time' => t('Time'),
);
}
/**
* Implements hook_date_formats().
*/
function os_base_date_formats() {
$condensed = array(
'day' => array(
'j F Y',
'l, M j',
'l, j M',
'n/j/Y',
'F jS, Y',
),
'time' => array(
'g:ia',
'H:i',
'g:ia T',
),
);
// Allow day formats to be used for core-supplied formats.
foreach (array('short', 'medium', 'long') as $format) {
$condensed[$format] = $condensed['day'];
}
$formats = array();
foreach ($condensed as $type => $f) {
foreach ($f as $format) {
$formats[] = array(
'type' => $type,
'format' => $format,
'locales' => array(),
);
}
}
return $formats;
}
/**
* Implements hook_image_styles_alter().
*
* Remove core's default 'medium', 'large' and 'thumbnail' styles if defined by
* core. Note, the media module adds a square_thumbnail of 180x180.
*/
function os_base_image_styles_alter(&$styles) {
if (variable_get('os_base_remove_core_image_styles', FALSE)) {
foreach (array('medium', 'large', 'thumbnail') as $remove) {
if (isset($styles[$remove]['module']) && $styles[$remove]['module'] == 'image' && isset($styles[$remove]['storage']) && $styles[$remove]['storage'] === IMAGE_STORAGE_DEFAULT) {
unset($styles[$remove]);
}
}
}
}
/**
* Preprocess page variables.
*/
function os_base_preprocess_page(&$vars) {
if (isset($vars['footer_message'])) {
// Replace @year with current year.
$vars['footer_message'] = str_replace('@year', date('Y'), $vars['footer_message']);
}
}
/**
* Preprocessor for theme('views_view').
*/
function os_base_preprocess_views_view(&$vars) {
$view = $vars['view'];
if ($view->base_table === 'node' && strpos($view->current_display, 'page') !== FALSE && empty($view->result) && empty($vars['empty'])) {
$types = node_type_get_types();
$output = array();
foreach ($view->filter as $handler) {
if ($handler->table === 'node' && $handler->field === 'type' && !empty($handler->options['value']) && $handler->options['operator'] === 'in') {
foreach (array_filter($handler->options['value']) as $type) {
$item = menu_get_item('node/add/' . strtr($type, array('_' => '-')));
if ($item && $item['access']) {
$output[] = t('Please <a href="!url">add your first @type</a> to get started.', array('@type' => $types[$type]->name, '!url' => url($item['path'])));
}
}
break;
}
}
$vars['empty'] = !empty($output) ? implode('<br />', $output) : t('There is currently no content to view in this section.');
}
}
/**
* Implements hook_user_default_permissions_alter().
*/
function os_base_user_default_permissions_alter(&$permissions) {
// This is a workaround that allows us to export permissions for modules
// without making them a hard dependency. This simply removes permissions
// whose modules are not currently enabled.
$modules_enabled = module_list();
foreach ($permissions as $key => $perm) {
if (empty($perm['module'])) {
continue;
}
if (!isset($modules_enabled[$perm['module']])) {
// Module isn't enabled; simply remove the permission.
unset($permissions[$key]);
}
}
}