5 * Deploy Managed UI module functions.
9 * Implements hook_permission().
11 function deploy_managed_ui_permission() {
13 'access managed aggregator ui' => array(
14 'title' => t('Access Managed Aggregator UI'),
15 'description' => t('Add items to the managed deployment aggregator when editing entities.'),
21 * Implements hook form_alter().
23 function deploy_managed_ui_form_alter(&$form, &$form_state, $form_id) {
25 if (!empty($form['#node_edit_form'])) {
26 deploy_managed_ui_form_elements($form, 'deploy_managed_ui_node_form_submit', TRUE
);
29 // For the rest we only support edit forms following the Entity API convention.
30 if (!empty($form['#entity_type'])) {
31 $entity_type = $form['#entity_type'];
32 if (isset($form[$entity_type]) && is_object($form[$entity_type]['#value'])) {
33 deploy_managed_ui_form_elements($form, 'deploy_managed_ui_entity_form_submit');
39 * Generates form elements for hook_form_alter() implementations to call.
41 function deploy_managed_ui_form_elements(&$form, $submit_handler, $vertical_tabs = FALSE
) {
48 if (!user_access('access managed aggregator ui')) {
52 $plans = deploy_manager_plan_get_options();
57 $form['deploy_managed_ui'] = array(
58 '#type' => 'fieldset',
59 '#title' => t('Deployment plans'),
60 '#collapsible' => TRUE
,
61 '#collapsed' => FALSE
,
62 '#group' => 'additional_settings',
64 // Skipping fancy JS for now.
67 'vertical-tabs' => drupal_get_path('module', 'deploy_managed_ui') . '/deploy_managed_ui.js',
75 $form['deploy_managed_ui']['text'] = array(
76 '#markup' => t('Select the plans to include these chanages in.'),
79 $form['deploy_managed_ui']['plans'] = array(
80 '#type' => 'checkboxes',
81 '#title' => t('Plans'),
85 if (!$vertical_tabs) {
86 $form['actions']['#weight'] = ($weight + 1);
89 $form['#submit'][] = $submit_handler;
93 * Submit handler for node forms supporting managed UI.
95 function deploy_managed_ui_node_form_submit(&$form, &$form_state) {
96 $form_state['node']->___deploy_plans
= array();
97 foreach ($form_state['values']['deploy_managed_ui']['plans'] as
$plan => $checked) {
99 $form_state['node']->___deploy_plans
[$plan] = $plan;
105 * Submit handler for entity forms supporting managed UI.
107 function deploy_managed_ui_entity_form_submit(&$form, &$form_state) {
108 $entity_type = $form['#entity_type'];
109 $entity = $form_state[$entity_type];
110 $form_state[$entity_type]->___deploy_plans
= array();
111 foreach ($form_state['values']['deploy_managed_ui']['plans'] as
$plan => $checked) {
113 $form_state[$entity_type]->___deploy_plans
[$plan] = $plan;
119 * Implements hook_entity_insert().
121 function deploy_managed_ui_entity_insert($entity, $type) {
122 _deploy_managed_ui_entity_save($entity, $type);
126 * Implements hook_entity_update().
128 function deploy_managed_ui_entity_update($entity, $type) {
129 _deploy_managed_ui_entity_save($entity, $type);
133 * Handled deployment plans attached to entities being saved.
136 * $entity The entity being saved.
138 * $entity_type The type of entity being saved.
140 function _deploy_managed_ui_entity_save($entity, $type) {
141 // Ignore all entities which don't have plans attached.
142 if (empty($entity->___deploy_plans
)) {
146 foreach ($entity->___deploy_plans as
$plan) {
147 deploy_manager_add_to_plan($plan, $type, $entity);