This repository has been archived by the owner on Jan 21, 2025. It is now read-only.
forked from skwashd/drupal-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.core.inc
172 lines (159 loc) · 5.4 KB
/
deploy.core.inc
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
<?php
/**
* @file
* Deploy module functions for core entities.
*/
/**
* @defgroup deploy_alter Deployment alterations
* @{
*/
/**
* Implements hook_entity_load().
*
* The 'parent' property isn't attached when terms are loaded. Deploy needs that
* variable to correctly deploy terms.
*/
function taxonomy_entity_load(&$entities, $entity_type) {
if ($entity_type == 'taxonomy_term') {
foreach ($entities as &$entity) {
if (!isset($entity->parent)) {
$parents = taxonomy_get_parents($entity->tid);
if (!empty($parents)) {
$entity->parent = array();
foreach ($parents as $parent) {
$entity->parent[] = $parent->tid;
}
}
}
}
}
}
/**
* Implements hook_deploy_entity_alter().
*/
function file_deploy_entity_alter(&$entity, $entity_type) {
if ($entity_type == 'file') {
if (!isset($entity->file_contents)) {
$entity->file_contents = base64_encode(file_get_contents($entity->uri));
}
}
}
/**
* Implements hook_deploy_entity_alter().
*
* This hook will go through all fields for an entity and invoke a new hook for
* all field modules. This saves a lot of work for each field implementaor.
*/
function field_deploy_entity_alter(&$entity, $entity_type) {
if (empty($entity) || empty($entity_type)) {
return;
}
$dependencies = array();
list(, , $bundle_name) = entity_extract_ids($entity_type, $entity);
$instances = field_info_instances($entity_type, $bundle_name);
foreach ($instances as $field_name => $instance) {
$field = field_info_field($field_name);
foreach ($entity->{$field_name} as $langcode => &$items) {
foreach ($items as &$item) {
// This can potentially save *a lot* of bandwidth, since these values
// aren't really needed when deploying.
foreach (array('safe_value', 'safe_summary') as $key) {
if (isset($item[$key])) {
unset($item[$key]);
}
}
}
// TODO: Can we do this with drupal_alter()? Reason for this quick and
// mashup is because I want to keep the argument order consistent between
// field hooks, and still possibility to alter arguments.
$function = $field['module'] . '_deploy_field_alter';
if (function_exists($function)) {
$function($entity_type, $entity, $field, $instance, $langcode, $items);
}
}
}
return $dependencies;
}
/**
* @} End of "Deployment alterations"
*/
/**
* @defgroup deploy_operations Bulk operations
* @{
*/
/**
* Implements hook_node_operations().
*/
function deploy_node_operations() {
$operations = array();
$options = deploy_manager_plan_get_options();
foreach ($options as $plan_name => $plan_title) {
$operations['deploy:add:' . $plan_name] = array(
'label' => $plan_title,
'callback' => 'deploy_node_operation_add_to_managed_plan',
'callback arguments' => array('plan_name' => $plan_name),
);
$operations['deploy:delete:' . $plan_name] = array(
'label' => $plan_title,
'callback' => 'deploy_node_operation_delete_from_managed_plan',
'callback arguments' => array('plan_name' => $plan_name),
);
}
return $operations;
}
/**
* Node operation callback.
*/
function deploy_node_operation_add_to_managed_plan($nids, $plan_name) {
$plan = deploy_plan_load($plan_name);
foreach ($nids as $nid) {
$node = node_load($nid);
deploy_manager_add_to_plan($plan_name, 'node', $node);
}
$deploy_link = url("admin/structure/deploy/plans/list/$plan_name/deploy", array('query' => array('cancel_path' => 'admin/content')));
$overview_link = url('admin/structure/deploy');
drupal_set_message(t('Nodes were added to <a href="@overview">@plan</a>. You might want to <a href="@deploy">deploy the plan</a>.', array('@plan' => $plan->title, '@overview' => $overview_link, '@deploy' => $deploy_link)));
}
/**
* Node operation callback.
*/
function deploy_node_operation_delete_from_managed_plan($nids, $plan_name) {
$plan = deploy_plan_load($plan_name);
foreach ($nids as $nid) {
$node = node_load($nid);
deploy_manager_delete_from_plan($plan_name, 'node', $node);
}
$deploy_link = url("admin/structure/deploy/plans/list/$plan_name/deploy", array('query' => array('cancel_path' => 'admin/content')));
$overview_link = url('admin/structure/deploy');
drupal_set_message(t('Nodes were deleted from <a href="@overview">@plan</a>. You might want to <a href="@deploy">deploy the plan</a>.', array('@plan' => $plan->title, '@overview' => $overview_link, '@deploy' => $deploy_link)));
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function deploy_form_node_admin_content_alter(&$form, $form_state) {
if (empty($form['admin']['options']['operation']['#options'])) {
return;
}
$options = &$form['admin']['options']['operation']['#options'];
$group_add = t('Add to managed deployment plan');
$options[$group_add] = array();
$group_delete = t('Delete from managed deployment plan');
$options[$group_delete] = array();
foreach ($form['admin']['options']['operation']['#options'] as $key => $value) {
list($module) = explode(':', $key);
if ($module == 'deploy') {
list(, $op) = explode(':', $key);
unset($options[$key]);
if ($op == 'add') {
unset($options[$key]);
$options[$group_add][$key] = $value;
}
elseif ($op == 'delete') {
$options[$group_delete][$key] = $value;
}
}
}
}
/**
* @} End of "Bulk operations"
*/