You are here

deploy_adhoc_plan.rules.inc in Deploy - Content Staging 7.3

Same filename and directory in other branches
  1. 7.2 modules/deploy_adhoc_plan/deploy_adhoc_plan.rules.inc

Rules implementations for ad hoc plans.

File

modules/deploy_adhoc_plan/deploy_adhoc_plan.rules.inc
View source
<?php

/**
 * @file
 * Rules implementations for ad hoc plans.
 */

/**
 * Implements hook_rules_action_info().
 */
function deploy_adhoc_plan_rules_action_info() {
  return array(
    'deploy_adhoc_plan_rules_action_deploy_plan' => array(
      'label' => t('Deploy ad hoc plan'),
      'group' => t('Deploy'),
      'access callback' => 'deploy_adhoc_plan_session_exists',
    ),
    'deploy_adhoc_plan_rules_action_add_to_managed_plan' => array(
      'label' => t('Add entity to ad hoc deployment plan'),
      'group' => t('Deploy'),
      'access callback' => 'deploy_adhoc_plan_session_exists',
      'parameter' => array(
        'entity' => array(
          'type' => 'entity',
          'label' => t('Entity'),
          'description' => t('The entity that shall be added to the plan.'),
          'wrapped' => TRUE,
        ),
      ),
    ),
    'deploy_adhoc_plan_manager_action_delete_from_plan' => array(
      'label' => t('Remove entity from ad hoc deployment plan'),
      'group' => t('Deploy'),
      'access callback' => 'deploy_adhoc_plan_session_exists',
      'parameter' => array(
        'entity' => array(
          'type' => 'entity',
          'label' => t('Entity'),
          'description' => t('The entity that shall be removed from the plan.'),
          'wrapped' => TRUE,
        ),
      ),
    ),
    'deploy_adhoc_plan_action_move_to_adhoc' => array(
      'label' => t('Move an entity to ad hoc deployment plan'),
      'group' => t('Deploy'),
      'access callback' => 'deploy_adhoc_plan_session_exists',
      'parameter' => array(
        'entity' => array(
          'type' => 'entity',
          'label' => t('Entity'),
          'description' => t('The entity that shall be moved to ad hoc.'),
          'wrapped' => TRUE,
        ),
      ),
    ),
  );
}

/**
 * Action callback for the "Deploy a plan" action.
 */
function deploy_adhoc_plan_rules_action_deploy_plan($plan_name) {
  if (!empty($_SESSION['deploy_auto_plan_user_plan'])) {
    $plan = deploy_manager_plan_load($_SESSION['deploy_auto_plan_user_plan']);
    if ($plan) {
      $plan
        ->deploy();
      return;
    }
  }
  drupal_set_message(t('Cannot deploy ad hoc plan.'), 'warning');
}

/**
 * Action callback for the "Add to ad hoc deploy plan" action.
 */
function deploy_adhoc_plan_rules_action_add_to_managed_plan($entity_wrapper) {
  if (empty($_SESSION['deploy_auto_plan_user_plan']) || !deploy_manager_plan_load($_SESSION['deploy_auto_plan_user_plan'])) {
    drupal_set_message(t('No ad hoc plan to add to.'), 'warning', FALSE);
    return;
  }
  $entity_type = $entity_wrapper
    ->type();
  $entity = $entity_wrapper
    ->value();
  deploy_manager_add_to_plan($_SESSION['deploy_auto_plan_user_plan'], $entity_type, $entity);
}

/**
 * Action callback for the "Remove from ad hoc deploy plan" action.
 */
function deploy_adhoc_plan_manager_action_delete_from_plan($entity_wrapper) {
  if (empty($_SESSION['deploy_auto_plan_user_plan']) || !deploy_manager_plan_load($_SESSION['deploy_auto_plan_user_plan'])) {
    drupal_set_message(t('No ad hoc plan to remove from.'), 'warning', FALSE);
    return;
  }
  $entity_type = $entity_wrapper
    ->type();
  $entity = $entity_wrapper
    ->value();
  deploy_manager_delete_from_plan($_SESSION['deploy_auto_plan_user_plan'], $entity_type, $entity);
}

/**
 * Action callback for the "Move an entity to ad hoc deployment plan" action.
 */
function deploy_adhoc_plan_action_move_to_adhoc($dme) {
  if (empty($_SESSION['deploy_auto_plan_user_plan']) || !deploy_manager_plan_load($_SESSION['deploy_auto_plan_user_plan'])) {
    drupal_set_message(t('No ad hoc plan to add to.'), 'warning', FALSE);
    return;
  }
  $label = $dme
    ->label();
  $dme
    ->delete();
  drupal_set_message(t('Entity has been removed: @label', [
    '@label' => $label,
  ]));
  $type = $dme->entity_type
    ->value();
  $entity = entity_load_single($type, $dme->entity_id
    ->value());
  deploy_manager_add_to_plan($_SESSION['deploy_auto_plan_user_plan'], $type, entity_load_single($type, $dme->entity_id
    ->value()));
  drupal_set_message(t('Entity @label has been moved to the @plan plan.', array(
    '@label' => $entity->title,
    '@plan' => $_SESSION['deploy_auto_plan_user_plan'],
  )));
}

/**
 * Access callback to ensure an ad hoc plan is set for the current user.
 */
function deploy_adhoc_plan_session_exists() {
  if (!empty($_SESSION['deploy_auto_plan_user_plan'])) {
    return TRUE;
  }
  return FALSE;
}

Functions

Namesort descending Description
deploy_adhoc_plan_action_move_to_adhoc Action callback for the "Move an entity to ad hoc deployment plan" action.
deploy_adhoc_plan_manager_action_delete_from_plan Action callback for the "Remove from ad hoc deploy plan" action.
deploy_adhoc_plan_rules_action_add_to_managed_plan Action callback for the "Add to ad hoc deploy plan" action.
deploy_adhoc_plan_rules_action_deploy_plan Action callback for the "Deploy a plan" action.
deploy_adhoc_plan_rules_action_info Implements hook_rules_action_info().
deploy_adhoc_plan_session_exists Access callback to ensure an ad hoc plan is set for the current user.