diff --git a/deploy.core.inc b/deploy.core.inc index ef958f2..beaaaed 100644 --- a/deploy.core.inc +++ b/deploy.core.inc @@ -166,3 +166,108 @@ function deploy_form_node_admin_content_alter(&$form, $form_state) { /** * @} End of "Bulk operations" */ + +/** + * @defgroup deploy_actions Deploy core actions + * @{ + */ + +/** + * Implements hook_action_info(). + */ +function deploy_action_info() { + $actions = array(); + $actions['deploy_action_add_to_managed_plan'] = array( + 'type' => 'node', + 'label' => t('Add to managed deployment plan'), + 'configurable' => TRUE, + ); + $actions['deploy_action_delete_from_managed_plan'] = array( + 'type' => 'node', + 'label' => t('Delete from managed deployment plan'), + 'configurable' => TRUE, + ); + return $actions; +} + +/** + * Form constructor for the configuration of deploy_action_add_to_managed_plan. + * + * @see deploy_action_info() + * @see deploy_action_add_to_managed_plan_submit() + */ +function deploy_action_add_to_managed_plan_form($context) { + $options = deploy_manager_plan_get_options(); + + $form['plan'] = array( + '#title' => t('The plan to add the entity to.'), + '#type' => 'select', + '#options'=> $options, + '#default_value' => key($options), + ); + + return $form; +} + +/** + * Form submission handler for deploy_action_add_to_managed_plan_form(). + */ +function deploy_action_add_to_managed_plan_submit($form, $form_state) { + return array('plan' => $form_state['values']['plan']); +} + +/** + * Form constructor for the configuration of deploy_action_delete_from_managed_plan. + * + * @see deploy_action_info() + * @see deploy_action_delete_from_managed_plan_submit() + */ +function deploy_action_delete_from_managed_plan_form($context) { + $options = deploy_manager_plan_get_options(); + + $form['plan'] = array( + '#title' => t('The plan to remove the entity from.'), + '#type' => 'select', + '#options'=> $options, + '#default_value' => key($options), + ); + + return $form; +} + +/** + * Form submission handler for deploy_action_delete_from_managed_plan_form(). + */ +function deploy_action_delete_from_managed_plan_submit($form, $form_state) { + return array('plan' => $form_state['values']['plan']); +} + +/** + * Add a node to a deployment plan. + */ +function deploy_action_add_to_managed_plan($node, $context = array()) { + if (!deploy_plan_load($context['plan'])) { + watchdog('action', 'Cannot add to non-managed plan %name', array('%name' => $context['plan']), WATCHDOG_ERROR); + return; + } + deploy_manager_add_to_plan($context['plan'], 'node', $node); + + watchdog('action', 'Added node !nid to deployment plan @plan.', array('!nid' => $node->nid, '@plan' => $context['plan']), WATCHDOG_NOTICE); +} + +/** + * Delete a node from a deployment plan. + */ +function deploy_action_delete_from_managed_plan($node, $context = array()) { + if (!deploy_plan_load($context['plan'])) { + watchdog('action', 'Cannot delete from non-managed plan %name', array('%name' => $context['plan']), WATCHDOG_ERROR); + return; + } + deploy_manager_delete_from_plan($context['plan'], 'node', $node); + + watchdog('action', 'Deleted node !nid from deployment plan @plan.', array('!nid' => $node->nid, '@plan' => $context['plan']), WATCHDOG_NOTICE); +} + +/** + * @} End of "Deploy actions" + */