Issue #1008166 by sun, catch, rootatwc, Rob Loach, Jody Lynn: Actions should be a module.
parent
f846c6c190
commit
2edfc475e5
|
@ -1,387 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* This is the actions engine for executing stored actions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup actions Actions
|
|
||||||
* @{
|
|
||||||
* Functions that perform an action on a certain system object.
|
|
||||||
*
|
|
||||||
* Action functions are declared by modules by implementing hook_action_info().
|
|
||||||
* Modules can cause action functions to run by calling actions_do().
|
|
||||||
*
|
|
||||||
* Each action function takes two to four arguments:
|
|
||||||
* - $entity: The object that the action acts on, such as a node, comment, or
|
|
||||||
* user.
|
|
||||||
* - $context: Array of additional information about what triggered the action.
|
|
||||||
* - $a1, $a2: Optional additional information, which can be passed into
|
|
||||||
* actions_do() and will be passed along to the action function.
|
|
||||||
*
|
|
||||||
* @} End of "defgroup actions".
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs a given list of actions by executing their callback functions.
|
|
||||||
*
|
|
||||||
* Given the IDs of actions to perform, this function finds out what the
|
|
||||||
* callback functions for the actions are by querying the database. Then
|
|
||||||
* it calls each callback using the function call $function($object, $context,
|
|
||||||
* $a1, $a2), passing the input arguments of this function (see below) to the
|
|
||||||
* action function.
|
|
||||||
*
|
|
||||||
* @param $action_ids
|
|
||||||
* The IDs of the actions to perform. Can be a single action ID or an array
|
|
||||||
* of IDs. IDs of configurable actions must be given as numeric action IDs;
|
|
||||||
* IDs of non-configurable actions may be given as action function names.
|
|
||||||
* @param $object
|
|
||||||
* The object that the action will act on: a node, user, or comment object.
|
|
||||||
* @param $context
|
|
||||||
* Associative array containing extra information about what triggered
|
|
||||||
* the action call, with $context['hook'] giving the name of the hook
|
|
||||||
* that resulted in this call to actions_do().
|
|
||||||
* @param $a1
|
|
||||||
* Passed along to the callback.
|
|
||||||
* @param $a2
|
|
||||||
* Passed along to the callback.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* An associative array containing the results of the functions that
|
|
||||||
* perform the actions, keyed on action ID.
|
|
||||||
*
|
|
||||||
* @ingroup actions
|
|
||||||
*/
|
|
||||||
function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a2 = NULL) {
|
|
||||||
// $stack tracks the number of recursive calls.
|
|
||||||
static $stack;
|
|
||||||
$stack++;
|
|
||||||
if ($stack > variable_get('actions_max_stack', 35)) {
|
|
||||||
watchdog('actions', 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.', array(), WATCHDOG_ERROR);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$actions = array();
|
|
||||||
$available_actions = actions_list();
|
|
||||||
$actions_result = array();
|
|
||||||
if (is_array($action_ids)) {
|
|
||||||
$conditions = array();
|
|
||||||
foreach ($action_ids as $action_id) {
|
|
||||||
if (is_numeric($action_id)) {
|
|
||||||
$conditions[] = $action_id;
|
|
||||||
}
|
|
||||||
elseif (isset($available_actions[$action_id])) {
|
|
||||||
$actions[$action_id] = $available_actions[$action_id];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// When we have action instances we must go to the database to retrieve
|
|
||||||
// instance data.
|
|
||||||
if (!empty($conditions)) {
|
|
||||||
$query = db_select('actions');
|
|
||||||
$query->addField('actions', 'aid');
|
|
||||||
$query->addField('actions', 'type');
|
|
||||||
$query->addField('actions', 'callback');
|
|
||||||
$query->addField('actions', 'parameters');
|
|
||||||
$query->condition('aid', $conditions, 'IN');
|
|
||||||
$result = $query->execute();
|
|
||||||
foreach ($result as $action) {
|
|
||||||
$actions[$action->aid] = $action->parameters ? unserialize($action->parameters) : array();
|
|
||||||
$actions[$action->aid]['callback'] = $action->callback;
|
|
||||||
$actions[$action->aid]['type'] = $action->type;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fire actions, in no particular order.
|
|
||||||
foreach ($actions as $action_id => $params) {
|
|
||||||
// Configurable actions need parameters.
|
|
||||||
if (is_numeric($action_id)) {
|
|
||||||
$function = $params['callback'];
|
|
||||||
if (function_exists($function)) {
|
|
||||||
$context = array_merge($context, $params);
|
|
||||||
$actions_result[$action_id] = $function($object, $context, $a1, $a2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$actions_result[$action_id] = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Singleton action; $action_id is the function name.
|
|
||||||
else {
|
|
||||||
$actions_result[$action_id] = $action_id($object, $context, $a1, $a2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Optimized execution of a single action.
|
|
||||||
else {
|
|
||||||
// If it's a configurable action, retrieve stored parameters.
|
|
||||||
if (is_numeric($action_ids)) {
|
|
||||||
$action = db_query("SELECT callback, parameters FROM {actions} WHERE aid = :aid", array(':aid' => $action_ids))->fetchObject();
|
|
||||||
$function = $action->callback;
|
|
||||||
if (function_exists($function)) {
|
|
||||||
$context = array_merge($context, unserialize($action->parameters));
|
|
||||||
$actions_result[$action_ids] = $function($object, $context, $a1, $a2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$actions_result[$action_ids] = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Singleton action; $action_ids is the function name.
|
|
||||||
else {
|
|
||||||
if (function_exists($action_ids)) {
|
|
||||||
$actions_result[$action_ids] = $action_ids($object, $context, $a1, $a2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Set to avoid undefined index error messages later.
|
|
||||||
$actions_result[$action_ids] = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$stack--;
|
|
||||||
return $actions_result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Discovers all available actions by invoking hook_action_info().
|
|
||||||
*
|
|
||||||
* This function contrasts with actions_get_all_actions(); see the
|
|
||||||
* documentation of actions_get_all_actions() for an explanation.
|
|
||||||
*
|
|
||||||
* @param $reset
|
|
||||||
* Reset the action info static cache.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* An associative array keyed on action function name, with the same format
|
|
||||||
* as the return value of hook_action_info(), containing all
|
|
||||||
* modules' hook_action_info() return values as modified by any
|
|
||||||
* hook_action_info_alter() implementations.
|
|
||||||
*
|
|
||||||
* @see hook_action_info()
|
|
||||||
*/
|
|
||||||
function actions_list($reset = FALSE) {
|
|
||||||
$actions = &drupal_static(__FUNCTION__);
|
|
||||||
if (!isset($actions) || $reset) {
|
|
||||||
$actions = module_invoke_all('action_info');
|
|
||||||
drupal_alter('action_info', $actions);
|
|
||||||
}
|
|
||||||
|
|
||||||
// See module_implements() for an explanation of this cast.
|
|
||||||
return (array) $actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves all action instances from the database.
|
|
||||||
*
|
|
||||||
* This function differs from the actions_list() function, which gathers
|
|
||||||
* actions by invoking hook_action_info(). The actions returned by this
|
|
||||||
* function and the actions returned by actions_list() are partially
|
|
||||||
* synchronized. Non-configurable actions from hook_action_info()
|
|
||||||
* implementations are put into the database when actions_synchronize() is
|
|
||||||
* called, which happens when admin/config/system/actions is visited.
|
|
||||||
* Configurable actions are not added to the database until they are configured
|
|
||||||
* in the user interface, in which case a database row is created for each
|
|
||||||
* configuration of each action.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* Associative array keyed by numeric action ID. Each value is an associative
|
|
||||||
* array with keys 'callback', 'label', 'type' and 'configurable'.
|
|
||||||
*/
|
|
||||||
function actions_get_all_actions() {
|
|
||||||
$actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
|
|
||||||
foreach ($actions as &$action) {
|
|
||||||
$action['configurable'] = (bool) $action['parameters'];
|
|
||||||
unset($action['parameters']);
|
|
||||||
unset($action['aid']);
|
|
||||||
}
|
|
||||||
return $actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an associative array keyed by hashes of function names or IDs.
|
|
||||||
*
|
|
||||||
* Hashes are used to prevent actual function names from going out into HTML
|
|
||||||
* forms and coming back.
|
|
||||||
*
|
|
||||||
* @param $actions
|
|
||||||
* An associative array with function names or action IDs as keys
|
|
||||||
* and associative arrays with keys 'label', 'type', etc. as values.
|
|
||||||
* This is usually the output of actions_list() or actions_get_all_actions().
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* An associative array whose keys are hashes of the input array keys, and
|
|
||||||
* whose corresponding values are associative arrays with components
|
|
||||||
* 'callback', 'label', 'type', and 'configurable' from the input array.
|
|
||||||
*/
|
|
||||||
function actions_actions_map($actions) {
|
|
||||||
$actions_map = array();
|
|
||||||
foreach ($actions as $callback => $array) {
|
|
||||||
$key = drupal_hash_base64($callback);
|
|
||||||
$actions_map[$key]['callback'] = isset($array['callback']) ? $array['callback'] : $callback;
|
|
||||||
$actions_map[$key]['label'] = $array['label'];
|
|
||||||
$actions_map[$key]['type'] = $array['type'];
|
|
||||||
$actions_map[$key]['configurable'] = $array['configurable'];
|
|
||||||
}
|
|
||||||
return $actions_map;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an action array key (function or ID), given its hash.
|
|
||||||
*
|
|
||||||
* Faster than actions_actions_map() when you only need the function name or ID.
|
|
||||||
*
|
|
||||||
* @param $hash
|
|
||||||
* Hash of a function name or action ID array key. The array key
|
|
||||||
* is a key into the return value of actions_list() (array key is the action
|
|
||||||
* function name) or actions_get_all_actions() (array key is the action ID).
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* The corresponding array key, or FALSE if no match is found.
|
|
||||||
*/
|
|
||||||
function actions_function_lookup($hash) {
|
|
||||||
// Check for a function name match.
|
|
||||||
$actions_list = actions_list();
|
|
||||||
foreach ($actions_list as $function => $array) {
|
|
||||||
if (drupal_hash_base64($function) == $hash) {
|
|
||||||
return $function;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$aid = FALSE;
|
|
||||||
// Must be a configurable action; check database.
|
|
||||||
$result = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchAll(PDO::FETCH_ASSOC);
|
|
||||||
foreach ($result as $row) {
|
|
||||||
if (drupal_hash_base64($row['aid']) == $hash) {
|
|
||||||
$aid = $row['aid'];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $aid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronizes actions that are provided by modules in hook_action_info().
|
|
||||||
*
|
|
||||||
* Actions provided by modules in hook_action_info() implementations are
|
|
||||||
* synchronized with actions that are stored in the actions database table.
|
|
||||||
* This is necessary so that actions that do not require configuration can
|
|
||||||
* receive action IDs.
|
|
||||||
*
|
|
||||||
* @param $delete_orphans
|
|
||||||
* If TRUE, any actions that exist in the database but are no longer
|
|
||||||
* found in the code (for example, because the module that provides them has
|
|
||||||
* been disabled) will be deleted.
|
|
||||||
*/
|
|
||||||
function actions_synchronize($delete_orphans = FALSE) {
|
|
||||||
$actions_in_code = actions_list(TRUE);
|
|
||||||
$actions_in_db = db_query("SELECT aid, callback, label FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
|
|
||||||
|
|
||||||
// Go through all the actions provided by modules.
|
|
||||||
foreach ($actions_in_code as $callback => $array) {
|
|
||||||
// Ignore configurable actions since their instances get put in when the
|
|
||||||
// user adds the action.
|
|
||||||
if (!$array['configurable']) {
|
|
||||||
// If we already have an action ID for this action, no need to assign aid.
|
|
||||||
if (isset($actions_in_db[$callback])) {
|
|
||||||
unset($actions_in_db[$callback]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// This is a new singleton that we don't have an aid for; assign one.
|
|
||||||
db_insert('actions')
|
|
||||||
->fields(array(
|
|
||||||
'aid' => $callback,
|
|
||||||
'type' => $array['type'],
|
|
||||||
'callback' => $callback,
|
|
||||||
'parameters' => '',
|
|
||||||
'label' => $array['label'],
|
|
||||||
))
|
|
||||||
->execute();
|
|
||||||
watchdog('actions', "Action '%action' added.", array('%action' => $array['label']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Any actions that we have left in $actions_in_db are orphaned.
|
|
||||||
if ($actions_in_db) {
|
|
||||||
$orphaned = array_keys($actions_in_db);
|
|
||||||
|
|
||||||
if ($delete_orphans) {
|
|
||||||
$actions = db_query('SELECT aid, label FROM {actions} WHERE callback IN (:orphaned)', array(':orphaned' => $orphaned))->fetchAll();
|
|
||||||
foreach ($actions as $action) {
|
|
||||||
actions_delete($action->aid);
|
|
||||||
watchdog('actions', "Removed orphaned action '%action' from database.", array('%action' => $action->label));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$link = l(t('Remove orphaned actions'), 'admin/config/system/actions/orphan');
|
|
||||||
$count = count($actions_in_db);
|
|
||||||
$orphans = implode(', ', $orphaned);
|
|
||||||
watchdog('actions', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), WATCHDOG_INFO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves an action and its user-supplied parameter values to the database.
|
|
||||||
*
|
|
||||||
* @param $function
|
|
||||||
* The name of the function to be called when this action is performed.
|
|
||||||
* @param $type
|
|
||||||
* The type of action, to describe grouping and/or context, e.g., 'node',
|
|
||||||
* 'user', 'comment', or 'system'.
|
|
||||||
* @param $params
|
|
||||||
* An associative array with parameter names as keys and parameter values as
|
|
||||||
* values.
|
|
||||||
* @param $label
|
|
||||||
* A user-supplied label of this particular action, e.g., 'Send e-mail
|
|
||||||
* to Jim'.
|
|
||||||
* @param $aid
|
|
||||||
* The ID of this action. If omitted, a new action is created.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* The ID of the action.
|
|
||||||
*/
|
|
||||||
function actions_save($function, $type, $params, $label, $aid = NULL) {
|
|
||||||
// aid is the callback for singleton actions so we need to keep a separate
|
|
||||||
// table for numeric aids.
|
|
||||||
if (!$aid) {
|
|
||||||
$aid = db_next_id();
|
|
||||||
}
|
|
||||||
|
|
||||||
db_merge('actions')
|
|
||||||
->key(array('aid' => $aid))
|
|
||||||
->fields(array(
|
|
||||||
'callback' => $function,
|
|
||||||
'type' => $type,
|
|
||||||
'parameters' => serialize($params),
|
|
||||||
'label' => $label,
|
|
||||||
))
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
watchdog('actions', 'Action %action saved.', array('%action' => $label));
|
|
||||||
return $aid;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieves a single action from the database.
|
|
||||||
*
|
|
||||||
* @param $aid
|
|
||||||
* The ID of the action to retrieve.
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* The appropriate action row from the database as an object.
|
|
||||||
*/
|
|
||||||
function actions_load($aid) {
|
|
||||||
return db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetchObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes a single action from the database.
|
|
||||||
*
|
|
||||||
* @param $aid
|
|
||||||
* The ID of the action to delete.
|
|
||||||
*/
|
|
||||||
function actions_delete($aid) {
|
|
||||||
db_delete('actions')
|
|
||||||
->condition('aid', $aid)
|
|
||||||
->execute();
|
|
||||||
module_invoke_all('actions_delete', $aid);
|
|
||||||
}
|
|
||||||
|
|
|
@ -3190,7 +3190,7 @@ function drupal_classloader_register($name, $path) {
|
||||||
* // $stack tracks the number of recursive calls.
|
* // $stack tracks the number of recursive calls.
|
||||||
* static $stack;
|
* static $stack;
|
||||||
* $stack++;
|
* $stack++;
|
||||||
* if ($stack > variable_get('actions_max_stack', 35)) {
|
* if ($stack > variable_get('action_max_stack', 35)) {
|
||||||
* ...
|
* ...
|
||||||
* return;
|
* return;
|
||||||
* }
|
* }
|
||||||
|
|
|
@ -4871,7 +4871,6 @@ function _drupal_bootstrap_code() {
|
||||||
require_once DRUPAL_ROOT . '/core/includes/image.inc';
|
require_once DRUPAL_ROOT . '/core/includes/image.inc';
|
||||||
require_once DRUPAL_ROOT . '/core/includes/form.inc';
|
require_once DRUPAL_ROOT . '/core/includes/form.inc';
|
||||||
require_once DRUPAL_ROOT . '/core/includes/mail.inc';
|
require_once DRUPAL_ROOT . '/core/includes/mail.inc';
|
||||||
require_once DRUPAL_ROOT . '/core/includes/actions.inc';
|
|
||||||
require_once DRUPAL_ROOT . '/core/includes/ajax.inc';
|
require_once DRUPAL_ROOT . '/core/includes/ajax.inc';
|
||||||
require_once DRUPAL_ROOT . '/core/includes/token.inc';
|
require_once DRUPAL_ROOT . '/core/includes/token.inc';
|
||||||
require_once DRUPAL_ROOT . '/core/includes/errors.inc';
|
require_once DRUPAL_ROOT . '/core/includes/errors.inc';
|
||||||
|
|
|
@ -0,0 +1,280 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Admin page callbacks for the Action module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Menu callback; Displays an overview of available and configured actions.
|
||||||
|
*/
|
||||||
|
function action_admin_manage() {
|
||||||
|
action_synchronize();
|
||||||
|
$actions = action_list();
|
||||||
|
$actions_map = action_actions_map($actions);
|
||||||
|
$options = array();
|
||||||
|
$unconfigurable = array();
|
||||||
|
|
||||||
|
foreach ($actions_map as $key => $array) {
|
||||||
|
if ($array['configurable']) {
|
||||||
|
$options[$key] = $array['label'] . '...';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$unconfigurable[] = $array;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = array();
|
||||||
|
$instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
|
||||||
|
$header = array(
|
||||||
|
array('data' => t('Action type'), 'field' => 'type'),
|
||||||
|
array('data' => t('Label'), 'field' => 'label'),
|
||||||
|
array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
|
||||||
|
);
|
||||||
|
$query = db_select('actions')
|
||||||
|
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
||||||
|
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
||||||
|
$result = $query
|
||||||
|
->fields('actions')
|
||||||
|
->limit(50)
|
||||||
|
->orderByHeader($header)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
foreach ($result as $action) {
|
||||||
|
$row[] = array(
|
||||||
|
array('data' => $action->type),
|
||||||
|
array('data' => check_plain($action->label)),
|
||||||
|
array('data' => $action->parameters ? l(t('configure'), "admin/config/system/actions/configure/$action->aid") : ''),
|
||||||
|
array('data' => $action->parameters ? l(t('delete'), "admin/config/system/actions/delete/$action->aid") : '')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($row) {
|
||||||
|
$pager = theme('pager');
|
||||||
|
if (!empty($pager)) {
|
||||||
|
$row[] = array(array('data' => $pager, 'colspan' => '3'));
|
||||||
|
}
|
||||||
|
$build['action_header'] = array('#markup' => '<h3>' . t('Available actions:') . '</h3>');
|
||||||
|
$build['action_table'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $row)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($actions_map) {
|
||||||
|
$build['action_admin_manage_form'] = drupal_get_form('action_admin_manage_form', $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $build;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the form for the actions overview page.
|
||||||
|
*
|
||||||
|
* @param $form_state
|
||||||
|
* An associative array containing the current state of the form; not used.
|
||||||
|
* @param $options
|
||||||
|
* An array of configurable actions.
|
||||||
|
* @return
|
||||||
|
* Form definition.
|
||||||
|
*
|
||||||
|
* @ingroup forms
|
||||||
|
* @see action_admin_manage_form_submit()
|
||||||
|
*/
|
||||||
|
function action_admin_manage_form($form, &$form_state, $options = array()) {
|
||||||
|
$form['parent'] = array(
|
||||||
|
'#type' => 'fieldset',
|
||||||
|
'#title' => t('Create an advanced action'),
|
||||||
|
'#attributes' => array('class' => array('container-inline')),
|
||||||
|
);
|
||||||
|
$form['parent']['action'] = array(
|
||||||
|
'#type' => 'select',
|
||||||
|
'#title' => t('Action'),
|
||||||
|
'#title_display' => 'invisible',
|
||||||
|
'#options' => $options,
|
||||||
|
'#empty_option' => t('Choose an advanced action'),
|
||||||
|
);
|
||||||
|
$form['parent']['actions'] = array('#type' => 'actions');
|
||||||
|
$form['parent']['actions']['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Create'),
|
||||||
|
);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission handler for action_admin_manage_form().
|
||||||
|
*/
|
||||||
|
function action_admin_manage_form_submit($form, &$form_state) {
|
||||||
|
if ($form_state['values']['action']) {
|
||||||
|
$form_state['redirect'] = 'admin/config/system/actions/configure/' . $form_state['values']['action'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form constructor for the configuration of a single action.
|
||||||
|
*
|
||||||
|
* We provide the "Description" field. The rest of the form is provided by the
|
||||||
|
* action. We then provide the Save button. Because we are combining unknown
|
||||||
|
* form elements with the action configuration form, we use an 'action_' prefix
|
||||||
|
* on our elements.
|
||||||
|
*
|
||||||
|
* @param $action
|
||||||
|
* Hash of an action ID or an integer. If it is a hash, we are
|
||||||
|
* creating a new instance. If it is an integer, we are editing an existing
|
||||||
|
* instance.
|
||||||
|
*
|
||||||
|
* @see action_admin_configure_validate()
|
||||||
|
* @see action_admin_configure_submit()
|
||||||
|
* @ingroup forms
|
||||||
|
*/
|
||||||
|
function action_admin_configure($form, &$form_state, $action = NULL) {
|
||||||
|
if ($action === NULL) {
|
||||||
|
drupal_goto('admin/config/system/actions');
|
||||||
|
}
|
||||||
|
|
||||||
|
$actions_map = action_actions_map(action_list());
|
||||||
|
$edit = array();
|
||||||
|
|
||||||
|
// Numeric action denotes saved instance of a configurable action.
|
||||||
|
if (is_numeric($action)) {
|
||||||
|
$aid = $action;
|
||||||
|
// Load stored parameter values from database.
|
||||||
|
$data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
|
||||||
|
$edit['action_label'] = $data->label;
|
||||||
|
$edit['action_type'] = $data->type;
|
||||||
|
$function = $data->callback;
|
||||||
|
$action = drupal_hash_base64($data->callback);
|
||||||
|
$params = unserialize($data->parameters);
|
||||||
|
if ($params) {
|
||||||
|
foreach ($params as $name => $val) {
|
||||||
|
$edit[$name] = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise, we are creating a new action instance.
|
||||||
|
else {
|
||||||
|
$function = $actions_map[$action]['callback'];
|
||||||
|
$edit['action_label'] = $actions_map[$action]['label'];
|
||||||
|
$edit['action_type'] = $actions_map[$action]['type'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$form['action_label'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Label'),
|
||||||
|
'#default_value' => $edit['action_label'],
|
||||||
|
'#maxlength' => '255',
|
||||||
|
'#description' => t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'),
|
||||||
|
'#weight' => -10
|
||||||
|
);
|
||||||
|
$action_form = $function . '_form';
|
||||||
|
$form = array_merge($form, $action_form($edit));
|
||||||
|
$form['action_type'] = array(
|
||||||
|
'#type' => 'value',
|
||||||
|
'#value' => $edit['action_type'],
|
||||||
|
);
|
||||||
|
$form['action_action'] = array(
|
||||||
|
'#type' => 'hidden',
|
||||||
|
'#value' => $action,
|
||||||
|
);
|
||||||
|
// $aid is set when configuring an existing action instance.
|
||||||
|
if (isset($aid)) {
|
||||||
|
$form['action_aid'] = array(
|
||||||
|
'#type' => 'hidden',
|
||||||
|
'#value' => $aid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$form['action_configured'] = array(
|
||||||
|
'#type' => 'hidden',
|
||||||
|
'#value' => '1',
|
||||||
|
);
|
||||||
|
$form['actions'] = array('#type' => 'actions');
|
||||||
|
$form['actions']['submit'] = array(
|
||||||
|
'#type' => 'submit',
|
||||||
|
'#value' => t('Save'),
|
||||||
|
'#weight' => 13
|
||||||
|
);
|
||||||
|
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form validation handler for action_admin_configure().
|
||||||
|
*
|
||||||
|
* @see action_admin_configure_submit()
|
||||||
|
*/
|
||||||
|
function action_admin_configure_validate($form, &$form_state) {
|
||||||
|
$function = action_function_lookup($form_state['values']['action_action']) . '_validate';
|
||||||
|
// Hand off validation to the action.
|
||||||
|
if (function_exists($function)) {
|
||||||
|
$function($form, $form_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission handler for action_admin_configure().
|
||||||
|
*
|
||||||
|
* @see action_admin_configure_validate()
|
||||||
|
*/
|
||||||
|
function action_admin_configure_submit($form, &$form_state) {
|
||||||
|
$function = action_function_lookup($form_state['values']['action_action']);
|
||||||
|
$submit_function = $function . '_submit';
|
||||||
|
|
||||||
|
// Action will return keyed array of values to store.
|
||||||
|
$params = $submit_function($form, $form_state);
|
||||||
|
$aid = isset($form_state['values']['action_aid']) ? $form_state['values']['action_aid'] : NULL;
|
||||||
|
|
||||||
|
action_save($function, $form_state['values']['action_type'], $params, $form_state['values']['action_label'], $aid);
|
||||||
|
drupal_set_message(t('The action has been successfully saved.'));
|
||||||
|
|
||||||
|
$form_state['redirect'] = 'admin/config/system/actions/manage';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the form for confirmation of deleting an action.
|
||||||
|
*
|
||||||
|
* @see action_admin_delete_form_submit()
|
||||||
|
* @ingroup forms
|
||||||
|
*/
|
||||||
|
function action_admin_delete_form($form, &$form_state, $action) {
|
||||||
|
$form['aid'] = array(
|
||||||
|
'#type' => 'hidden',
|
||||||
|
'#value' => $action->aid,
|
||||||
|
);
|
||||||
|
return confirm_form($form,
|
||||||
|
t('Are you sure you want to delete the action %action?', array('%action' => $action->label)),
|
||||||
|
'admin/config/system/actions/manage',
|
||||||
|
t('This cannot be undone.'),
|
||||||
|
t('Delete'),
|
||||||
|
t('Cancel')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form submission handler for action_admin_delete_form().
|
||||||
|
*/
|
||||||
|
function action_admin_delete_form_submit($form, &$form_state) {
|
||||||
|
$aid = $form_state['values']['aid'];
|
||||||
|
$action = action_load($aid);
|
||||||
|
action_delete($aid);
|
||||||
|
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $action->label));
|
||||||
|
drupal_set_message(t('Action %action was deleted', array('%action' => $action->label)));
|
||||||
|
$form_state['redirect'] = 'admin/config/system/actions/manage';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Post-deletion operations for deleting action orphans.
|
||||||
|
*
|
||||||
|
* @param $orphaned
|
||||||
|
* An array of orphaned actions.
|
||||||
|
*/
|
||||||
|
function action_admin_delete_orphans_post($orphaned) {
|
||||||
|
foreach ($orphaned as $callback) {
|
||||||
|
drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes actions that are in the database but not supported by any enabled module.
|
||||||
|
*/
|
||||||
|
function action_admin_remove_orphans() {
|
||||||
|
action_synchronize(TRUE);
|
||||||
|
drupal_goto('admin/config/system/actions/manage');
|
||||||
|
}
|
|
@ -0,0 +1,98 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Hooks provided by the Actions module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Declares information about actions.
|
||||||
|
*
|
||||||
|
* Any module can define actions, and then call actions_do() to make those
|
||||||
|
* actions happen in response to events.
|
||||||
|
*
|
||||||
|
* An action consists of two or three parts:
|
||||||
|
* - an action definition (returned by this hook)
|
||||||
|
* - a function which performs the action (which by convention is named
|
||||||
|
* MODULE_description-of-function_action)
|
||||||
|
* - an optional form definition function that defines a configuration form
|
||||||
|
* (which has the name of the action function with '_form' appended to it.)
|
||||||
|
*
|
||||||
|
* The action function takes two to four arguments, which come from the input
|
||||||
|
* arguments to actions_do().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* An associative array of action descriptions. The keys of the array
|
||||||
|
* are the names of the action functions, and each corresponding value
|
||||||
|
* is an associative array with the following key-value pairs:
|
||||||
|
* - 'type': The type of object this action acts upon. Core actions have types
|
||||||
|
* 'node', 'user', 'comment', and 'system'.
|
||||||
|
* - 'label': The human-readable name of the action, which should be passed
|
||||||
|
* through the t() function for translation.
|
||||||
|
* - 'configurable': If FALSE, then the action doesn't require any extra
|
||||||
|
* configuration. If TRUE, then your module must define a form function with
|
||||||
|
* the same name as the action function with '_form' appended (e.g., the
|
||||||
|
* form for 'node_assign_owner_action' is 'node_assign_owner_action_form'.)
|
||||||
|
* This function takes $context as its only parameter, and is paired with
|
||||||
|
* the usual _submit function, and possibly a _validate function.
|
||||||
|
* - 'triggers': An array of the events (that is, hooks) that can trigger this
|
||||||
|
* action. For example: array('node_insert', 'user_update'). You can also
|
||||||
|
* declare support for any trigger by returning array('any') for this value.
|
||||||
|
* - 'behavior': (optional) A machine-readable array of behaviors of this
|
||||||
|
* action, used to signal additionally required actions that may need to be
|
||||||
|
* triggered. Modules that are processing actions should take special care
|
||||||
|
* for the "presave" hook, in which case a dependent "save" action should
|
||||||
|
* NOT be invoked.
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function hook_action_info() {
|
||||||
|
return array(
|
||||||
|
'comment_unpublish_action' => array(
|
||||||
|
'type' => 'comment',
|
||||||
|
'label' => t('Unpublish comment'),
|
||||||
|
'configurable' => FALSE,
|
||||||
|
'behavior' => array('changes_property'),
|
||||||
|
'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
|
||||||
|
),
|
||||||
|
'comment_unpublish_by_keyword_action' => array(
|
||||||
|
'type' => 'comment',
|
||||||
|
'label' => t('Unpublish comment containing keyword(s)'),
|
||||||
|
'configurable' => TRUE,
|
||||||
|
'behavior' => array('changes_property'),
|
||||||
|
'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
|
||||||
|
),
|
||||||
|
'comment_save_action' => array(
|
||||||
|
'type' => 'comment',
|
||||||
|
'label' => t('Save comment'),
|
||||||
|
'configurable' => FALSE,
|
||||||
|
'triggers' => array('comment_insert', 'comment_update'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alters the actions declared by another module.
|
||||||
|
*
|
||||||
|
* Called by action_list() to allow modules to alter the return values from
|
||||||
|
* implementations of hook_action_info().
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function hook_action_info_alter(&$actions) {
|
||||||
|
$actions['node_unpublish_action']['label'] = t('Unpublish and remove from public view.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes code after an action is deleted.
|
||||||
|
*
|
||||||
|
* @param $aid
|
||||||
|
* The action ID.
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function hook_action_delete($aid) {
|
||||||
|
db_delete('actions_assignments')
|
||||||
|
->condition('aid', $aid)
|
||||||
|
->execute();
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
name = Actions
|
||||||
|
description = Perform tasks on specific events triggered within the system.
|
||||||
|
package = Core
|
||||||
|
version = VERSION
|
||||||
|
core = 8.x
|
||||||
|
configure = admin/config/system/actions
|
|
@ -0,0 +1,54 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* Install, update and uninstall functions for the Actions module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_schema().
|
||||||
|
*/
|
||||||
|
function action_schema() {
|
||||||
|
// 'action' is a reserved SQL keyword.
|
||||||
|
$schema['actions'] = array(
|
||||||
|
'description' => 'Stores action information.',
|
||||||
|
'fields' => array(
|
||||||
|
'aid' => array(
|
||||||
|
'description' => 'Primary Key: Unique action ID.',
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 255,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '0',
|
||||||
|
),
|
||||||
|
'type' => array(
|
||||||
|
'description' => 'The object that that action acts on (node, user, comment, system or custom types.)',
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 32,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
'callback' => array(
|
||||||
|
'description' => 'The callback function that executes when the action runs.',
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 255,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '',
|
||||||
|
),
|
||||||
|
'parameters' => array(
|
||||||
|
'description' => 'Parameters to be passed to the callback function.',
|
||||||
|
'type' => 'blob',
|
||||||
|
'not null' => TRUE,
|
||||||
|
'size' => 'big',
|
||||||
|
),
|
||||||
|
'label' => array(
|
||||||
|
'description' => 'Label of the action.',
|
||||||
|
'type' => 'varchar',
|
||||||
|
'length' => 255,
|
||||||
|
'not null' => TRUE,
|
||||||
|
'default' => '0',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
'primary key' => array('aid'),
|
||||||
|
);
|
||||||
|
return $schema;
|
||||||
|
}
|
|
@ -0,0 +1,713 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* This is the Actions module for executing stored actions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup actions Actions
|
||||||
|
* @{
|
||||||
|
* Functions that perform an action on a certain system object.
|
||||||
|
*
|
||||||
|
* Action functions are declared by modules by implementing hook_action_info().
|
||||||
|
* Modules can cause action functions to run by calling actions_do().
|
||||||
|
*
|
||||||
|
* Each action function takes two to four arguments:
|
||||||
|
* - $entity: The object that the action acts on, such as a node, comment, or
|
||||||
|
* user.
|
||||||
|
* - $context: Array of additional information about what triggered the action.
|
||||||
|
* - $a1, $a2: Optional additional information, which can be passed into
|
||||||
|
* actions_do() and will be passed along to the action function.
|
||||||
|
*
|
||||||
|
* @} End of "defgroup actions".
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_help().
|
||||||
|
*/
|
||||||
|
function action_help($path, $arg) {
|
||||||
|
switch ($path) {
|
||||||
|
case 'admin/help#action':
|
||||||
|
$output = '<p>' . t('Actions are individual tasks that the system can do, such as unpublishing a piece of content or banning a user. Other modules can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions. Visit the <a href="@actions">Actions page</a> to configure actions.', array('@actions' => url('admin/config/system/actions'))) . '</p>';
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
case 'admin/config/system/actions':
|
||||||
|
case 'admin/config/system/actions/manage':
|
||||||
|
$output = '<p>' . t('There are two types of actions: simple and advanced. Simple actions do not require any additional configuration and are listed here automatically. Advanced actions need to be created and configured before they can be used because they have options that need to be specified; for example, sending an e-mail to a specified address or unpublishing content containing certain words. To create an advanced action, select the action from the drop-down list in the advanced action section below and click the <em>Create</em> button.') . '</p>';
|
||||||
|
return $output;
|
||||||
|
|
||||||
|
case 'admin/config/system/actions/configure':
|
||||||
|
return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended in order to better identify the precise action taking place.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_permission().
|
||||||
|
*/
|
||||||
|
function action_permission() {
|
||||||
|
return array(
|
||||||
|
'administer actions' => array(
|
||||||
|
'title' => t('Administer actions'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_menu().
|
||||||
|
*/
|
||||||
|
function action_menu() {
|
||||||
|
$items['admin/config/system/actions'] = array(
|
||||||
|
'title' => 'Actions',
|
||||||
|
'description' => 'Manage the actions defined for your site.',
|
||||||
|
'access arguments' => array('administer actions'),
|
||||||
|
'page callback' => 'action_admin_manage',
|
||||||
|
'file' => 'action.admin.inc',
|
||||||
|
);
|
||||||
|
$items['admin/config/system/actions/manage'] = array(
|
||||||
|
'title' => 'Manage actions',
|
||||||
|
'description' => 'Manage the actions defined for your site.',
|
||||||
|
'page callback' => 'action_admin_manage',
|
||||||
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||||
|
'weight' => -2,
|
||||||
|
'file' => 'action.admin.inc',
|
||||||
|
);
|
||||||
|
$items['admin/config/system/actions/configure'] = array(
|
||||||
|
'title' => 'Configure an advanced action',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('action_admin_configure'),
|
||||||
|
'access arguments' => array('administer actions'),
|
||||||
|
'type' => MENU_VISIBLE_IN_BREADCRUMB,
|
||||||
|
'file' => 'action.admin.inc',
|
||||||
|
);
|
||||||
|
$items['admin/config/system/actions/delete/%action'] = array(
|
||||||
|
'title' => 'Delete action',
|
||||||
|
'description' => 'Delete an action.',
|
||||||
|
'page callback' => 'drupal_get_form',
|
||||||
|
'page arguments' => array('action_admin_delete_form', 5),
|
||||||
|
'access arguments' => array('administer actions'),
|
||||||
|
'file' => 'action.admin.inc',
|
||||||
|
);
|
||||||
|
$items['admin/config/system/actions/orphan'] = array(
|
||||||
|
'title' => 'Remove orphans',
|
||||||
|
'page callback' => 'action_admin_remove_orphans',
|
||||||
|
'access arguments' => array('administer actions'),
|
||||||
|
'type' => MENU_CALLBACK,
|
||||||
|
'file' => 'action.admin.inc',
|
||||||
|
);
|
||||||
|
return $items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_rebuild().
|
||||||
|
*/
|
||||||
|
function action_rebuild() {
|
||||||
|
// Synchronize any actions that were added or removed.
|
||||||
|
action_synchronize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs a given list of actions by executing their callback functions.
|
||||||
|
*
|
||||||
|
* Given the IDs of actions to perform, this function finds out what the
|
||||||
|
* callback functions for the actions are by querying the database. Then
|
||||||
|
* it calls each callback using the function call $function($object, $context,
|
||||||
|
* $a1, $a2), passing the input arguments of this function (see below) to the
|
||||||
|
* action function.
|
||||||
|
*
|
||||||
|
* @param $action_ids
|
||||||
|
* The IDs of the actions to perform. Can be a single action ID or an array
|
||||||
|
* of IDs. IDs of configurable actions must be given as numeric action IDs;
|
||||||
|
* IDs of non-configurable actions may be given as action function names.
|
||||||
|
* @param $object
|
||||||
|
* The object that the action will act on: a node, user, or comment object.
|
||||||
|
* @param $context
|
||||||
|
* Associative array containing extra information about what triggered
|
||||||
|
* the action call, with $context['hook'] giving the name of the hook
|
||||||
|
* that resulted in this call to actions_do(). Additional parameters
|
||||||
|
* will be used as the data for token replacement.
|
||||||
|
* @param $a1
|
||||||
|
* Passed along to the callback.
|
||||||
|
* @param $a2
|
||||||
|
* Passed along to the callback.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* An associative array containing the results of the functions that
|
||||||
|
* perform the actions, keyed on action ID.
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a2 = NULL) {
|
||||||
|
// $stack tracks the number of recursive calls.
|
||||||
|
static $stack;
|
||||||
|
$stack++;
|
||||||
|
if ($stack > variable_get('action_max_stack', 35)) {
|
||||||
|
watchdog('action', 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.', array(), WATCHDOG_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$actions = array();
|
||||||
|
$available_actions = action_list();
|
||||||
|
$result = array();
|
||||||
|
if (is_array($action_ids)) {
|
||||||
|
$conditions = array();
|
||||||
|
foreach ($action_ids as $action_id) {
|
||||||
|
if (is_numeric($action_id)) {
|
||||||
|
$conditions[] = $action_id;
|
||||||
|
}
|
||||||
|
elseif (isset($available_actions[$action_id])) {
|
||||||
|
$actions[$action_id] = $available_actions[$action_id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When we have action instances we must go to the database to retrieve
|
||||||
|
// instance data.
|
||||||
|
if (!empty($conditions)) {
|
||||||
|
$query = db_select('actions');
|
||||||
|
$query->addField('actions', 'aid');
|
||||||
|
$query->addField('actions', 'type');
|
||||||
|
$query->addField('actions', 'callback');
|
||||||
|
$query->addField('actions', 'parameters');
|
||||||
|
$query->condition('aid', $conditions, 'IN');
|
||||||
|
$result = $query->execute();
|
||||||
|
foreach ($result as $action) {
|
||||||
|
$actions[$action->aid] = $action->parameters ? unserialize($action->parameters) : array();
|
||||||
|
$actions[$action->aid]['callback'] = $action->callback;
|
||||||
|
$actions[$action->aid]['type'] = $action->type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fire actions, in no particular order.
|
||||||
|
foreach ($actions as $action_id => $params) {
|
||||||
|
// Configurable actions need parameters.
|
||||||
|
if (is_numeric($action_id)) {
|
||||||
|
$function = $params['callback'];
|
||||||
|
if (function_exists($function)) {
|
||||||
|
$context = array_merge($context, $params);
|
||||||
|
$result[$action_id] = $function($object, $context, $a1, $a2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$result[$action_id] = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Singleton action; $action_id is the function name.
|
||||||
|
else {
|
||||||
|
$result[$action_id] = $action_id($object, $context, $a1, $a2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Optimized execution of a single action.
|
||||||
|
else {
|
||||||
|
// If it's a configurable action, retrieve stored parameters.
|
||||||
|
if (is_numeric($action_ids)) {
|
||||||
|
$action = db_query("SELECT callback, parameters FROM {actions} WHERE aid = :aid", array(':aid' => $action_ids))->fetchObject();
|
||||||
|
$function = $action->callback;
|
||||||
|
if (function_exists($function)) {
|
||||||
|
$context = array_merge($context, unserialize($action->parameters));
|
||||||
|
$result[$action_ids] = $function($object, $context, $a1, $a2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$result[$action_ids] = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Singleton action; $action_ids is the function name.
|
||||||
|
else {
|
||||||
|
if (function_exists($action_ids)) {
|
||||||
|
$result[$action_ids] = $action_ids($object, $context, $a1, $a2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Set to avoid undefined index error messages later.
|
||||||
|
$result[$action_ids] = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$stack--;
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Discovers all available actions by invoking hook_action_info().
|
||||||
|
*
|
||||||
|
* This function contrasts with action_get_all_actions(); see the
|
||||||
|
* documentation of action_get_all_actions() for an explanation.
|
||||||
|
*
|
||||||
|
* @param $reset
|
||||||
|
* Reset the action info static cache.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* An associative array keyed on action function name, with the same format
|
||||||
|
* as the return value of hook_action_info(), containing all
|
||||||
|
* modules' hook_action_info() return values as modified by any
|
||||||
|
* hook_action_info_alter() implementations.
|
||||||
|
*
|
||||||
|
* @see hook_action_info()
|
||||||
|
*/
|
||||||
|
function action_list($reset = FALSE) {
|
||||||
|
$actions = &drupal_static(__FUNCTION__);
|
||||||
|
if (!isset($actions) || $reset) {
|
||||||
|
$actions = module_invoke_all('action_info');
|
||||||
|
drupal_alter('action_info', $actions);
|
||||||
|
}
|
||||||
|
|
||||||
|
// See module_implements() for an explanation of this cast.
|
||||||
|
return (array) $actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all action instances from the database.
|
||||||
|
*
|
||||||
|
* This function differs from the action_list() function, which gathers
|
||||||
|
* actions by invoking hook_action_info(). The actions returned by this
|
||||||
|
* function and the actions returned by action_list() are partially
|
||||||
|
* synchronized. Non-configurable actions from hook_action_info()
|
||||||
|
* implementations are put into the database when action_synchronize() is
|
||||||
|
* called, which happens when admin/config/system/actions is visited.
|
||||||
|
* Configurable actions are not added to the database until they are configured
|
||||||
|
* in the user interface, in which case a database row is created for each
|
||||||
|
* configuration of each action.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Associative array keyed by numeric action ID. Each value is an associative
|
||||||
|
* array with keys 'callback', 'label', 'type' and 'configurable'.
|
||||||
|
*/
|
||||||
|
function action_get_all_actions() {
|
||||||
|
$actions = db_query("SELECT aid, type, callback, parameters, label FROM {actions}")->fetchAllAssoc('aid', PDO::FETCH_ASSOC);
|
||||||
|
foreach ($actions as &$action) {
|
||||||
|
$action['configurable'] = (bool) $action['parameters'];
|
||||||
|
unset($action['parameters']);
|
||||||
|
unset($action['aid']);
|
||||||
|
}
|
||||||
|
return $actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an associative array keyed by hashes of function names or IDs.
|
||||||
|
*
|
||||||
|
* Hashes are used to prevent actual function names from going out into HTML
|
||||||
|
* forms and coming back.
|
||||||
|
*
|
||||||
|
* @param $actions
|
||||||
|
* An associative array with function names or action IDs as keys
|
||||||
|
* and associative arrays with keys 'label', 'type', etc. as values.
|
||||||
|
* This is usually the output of action_list() or action_get_all_actions().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* An associative array whose keys are hashes of the input array keys, and
|
||||||
|
* whose corresponding values are associative arrays with components
|
||||||
|
* 'callback', 'label', 'type', and 'configurable' from the input array.
|
||||||
|
*/
|
||||||
|
function action_actions_map($actions) {
|
||||||
|
$actions_map = array();
|
||||||
|
foreach ($actions as $callback => $array) {
|
||||||
|
$key = drupal_hash_base64($callback);
|
||||||
|
$actions_map[$key]['callback'] = isset($array['callback']) ? $array['callback'] : $callback;
|
||||||
|
$actions_map[$key]['label'] = $array['label'];
|
||||||
|
$actions_map[$key]['type'] = $array['type'];
|
||||||
|
$actions_map[$key]['configurable'] = $array['configurable'];
|
||||||
|
}
|
||||||
|
return $actions_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an action array key (function or ID), given its hash.
|
||||||
|
*
|
||||||
|
* Faster than action_actions_map() when you only need the function name or ID.
|
||||||
|
*
|
||||||
|
* @param $hash
|
||||||
|
* Hash of a function name or action ID array key. The array key
|
||||||
|
* is a key into the return value of action_list() (array key is the action
|
||||||
|
* function name) or action_get_all_actions() (array key is the action ID).
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The corresponding array key, or FALSE if no match is found.
|
||||||
|
*/
|
||||||
|
function action_function_lookup($hash) {
|
||||||
|
// Check for a function name match.
|
||||||
|
$actions_list = action_list();
|
||||||
|
foreach ($actions_list as $function => $array) {
|
||||||
|
if (drupal_hash_base64($function) == $hash) {
|
||||||
|
return $function;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$aid = FALSE;
|
||||||
|
// Must be a configurable action; check database.
|
||||||
|
$result = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchAll(PDO::FETCH_ASSOC);
|
||||||
|
foreach ($result as $row) {
|
||||||
|
if (drupal_hash_base64($row['aid']) == $hash) {
|
||||||
|
$aid = $row['aid'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Synchronizes actions that are provided by modules in hook_action_info().
|
||||||
|
*
|
||||||
|
* Actions provided by modules in hook_action_info() implementations are
|
||||||
|
* synchronized with actions that are stored in the actions database table.
|
||||||
|
* This is necessary so that actions that do not require configuration can
|
||||||
|
* receive action IDs.
|
||||||
|
*
|
||||||
|
* @param $delete_orphans
|
||||||
|
* If TRUE, any actions that exist in the database but are no longer
|
||||||
|
* found in the code (for example, because the module that provides them has
|
||||||
|
* been disabled) will be deleted.
|
||||||
|
*/
|
||||||
|
function action_synchronize($delete_orphans = FALSE) {
|
||||||
|
$actions_in_code = action_list(TRUE);
|
||||||
|
$actions_in_db = db_query("SELECT aid, callback, label FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
|
||||||
|
|
||||||
|
// Go through all the actions provided by modules.
|
||||||
|
foreach ($actions_in_code as $callback => $array) {
|
||||||
|
// Ignore configurable actions since their instances get put in when the
|
||||||
|
// user adds the action.
|
||||||
|
if (!$array['configurable']) {
|
||||||
|
// If we already have an action ID for this action, no need to assign aid.
|
||||||
|
if (isset($actions_in_db[$callback])) {
|
||||||
|
unset($actions_in_db[$callback]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// This is a new singleton that we don't have an aid for; assign one.
|
||||||
|
db_insert('actions')
|
||||||
|
->fields(array(
|
||||||
|
'aid' => $callback,
|
||||||
|
'type' => $array['type'],
|
||||||
|
'callback' => $callback,
|
||||||
|
'parameters' => '',
|
||||||
|
'label' => $array['label'],
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
watchdog('action', "Action '%action' added.", array('%action' => $array['label']));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Any actions that we have left in $actions_in_db are orphaned.
|
||||||
|
if ($actions_in_db) {
|
||||||
|
$orphaned = array_keys($actions_in_db);
|
||||||
|
|
||||||
|
if ($delete_orphans) {
|
||||||
|
$actions = db_query('SELECT aid, label FROM {actions} WHERE callback IN (:orphaned)', array(':orphaned' => $orphaned))->fetchAll();
|
||||||
|
foreach ($actions as $action) {
|
||||||
|
action_delete($action->aid);
|
||||||
|
watchdog('action', "Removed orphaned action '%action' from database.", array('%action' => $action->label));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$link = l(t('Remove orphaned actions'), 'admin/config/system/actions/orphan');
|
||||||
|
$count = count($actions_in_db);
|
||||||
|
$orphans = implode(', ', $orphaned);
|
||||||
|
watchdog('action', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), WATCHDOG_INFO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves an action and its user-supplied parameter values to the database.
|
||||||
|
*
|
||||||
|
* @param $function
|
||||||
|
* The name of the function to be called when this action is performed.
|
||||||
|
* @param $type
|
||||||
|
* The type of action, to describe grouping and/or context, e.g., 'node',
|
||||||
|
* 'user', 'comment', or 'system'.
|
||||||
|
* @param $params
|
||||||
|
* An associative array with parameter names as keys and parameter values as
|
||||||
|
* values.
|
||||||
|
* @param $label
|
||||||
|
* A user-supplied label of this particular action, e.g., 'Send e-mail
|
||||||
|
* to Jim'.
|
||||||
|
* @param $aid
|
||||||
|
* The ID of this action. If omitted, a new action is created.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The ID of the action.
|
||||||
|
*/
|
||||||
|
function action_save($function, $type, $params, $label, $aid = NULL) {
|
||||||
|
// aid is the callback for singleton actions so we need to keep a separate
|
||||||
|
// table for numeric aids.
|
||||||
|
if (!$aid) {
|
||||||
|
$aid = db_next_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
db_merge('actions')
|
||||||
|
->key(array('aid' => $aid))
|
||||||
|
->fields(array(
|
||||||
|
'callback' => $function,
|
||||||
|
'type' => $type,
|
||||||
|
'parameters' => serialize($params),
|
||||||
|
'label' => $label,
|
||||||
|
))
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
watchdog('action', 'Action %action saved.', array('%action' => $label));
|
||||||
|
return $aid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a single action from the database.
|
||||||
|
*
|
||||||
|
* @param $aid
|
||||||
|
* The ID of the action to retrieve.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The appropriate action row from the database as an object.
|
||||||
|
*/
|
||||||
|
function action_load($aid) {
|
||||||
|
return db_query("SELECT aid, type, callback, parameters, label FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetchObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a single action from the database.
|
||||||
|
*
|
||||||
|
* @param $aid
|
||||||
|
* The ID of the action to delete.
|
||||||
|
*/
|
||||||
|
function action_delete($aid) {
|
||||||
|
db_delete('actions')
|
||||||
|
->condition('aid', $aid)
|
||||||
|
->execute();
|
||||||
|
module_invoke_all('action_delete', $aid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_action_info().
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function action_action_info() {
|
||||||
|
return array(
|
||||||
|
'action_message_action' => array(
|
||||||
|
'type' => 'system',
|
||||||
|
'label' => t('Display a message to the user'),
|
||||||
|
'configurable' => TRUE,
|
||||||
|
'triggers' => array('any'),
|
||||||
|
),
|
||||||
|
'action_send_email_action' => array(
|
||||||
|
'type' => 'system',
|
||||||
|
'label' => t('Send e-mail'),
|
||||||
|
'configurable' => TRUE,
|
||||||
|
'triggers' => array('any'),
|
||||||
|
),
|
||||||
|
'action_goto_action' => array(
|
||||||
|
'type' => 'system',
|
||||||
|
'label' => t('Redirect to URL'),
|
||||||
|
'configurable' => TRUE,
|
||||||
|
'triggers' => array('any'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a form definition so the Send email action can be configured.
|
||||||
|
*
|
||||||
|
* @param $context
|
||||||
|
* Default values (if we are editing an existing action instance).
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* Form definition.
|
||||||
|
*
|
||||||
|
* @see action_send_email_action_validate()
|
||||||
|
* @see action_send_email_action_submit()
|
||||||
|
*/
|
||||||
|
function action_send_email_action_form($context) {
|
||||||
|
// Set default values for form.
|
||||||
|
if (!isset($context['recipient'])) {
|
||||||
|
$context['recipient'] = '';
|
||||||
|
}
|
||||||
|
if (!isset($context['subject'])) {
|
||||||
|
$context['subject'] = '';
|
||||||
|
}
|
||||||
|
if (!isset($context['message'])) {
|
||||||
|
$context['message'] = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$form['recipient'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Recipient'),
|
||||||
|
'#default_value' => $context['recipient'],
|
||||||
|
'#maxlength' => '254',
|
||||||
|
'#description' => t('The e-mail address to which the message should be sent OR enter [node:author:mail], [comment:author:mail], etc. if you would like to send an e-mail to the author of the original post.'),
|
||||||
|
);
|
||||||
|
$form['subject'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('Subject'),
|
||||||
|
'#default_value' => $context['subject'],
|
||||||
|
'#maxlength' => '254',
|
||||||
|
'#description' => t('The subject of the message.'),
|
||||||
|
);
|
||||||
|
$form['message'] = array(
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t('Message'),
|
||||||
|
'#default_value' => $context['message'],
|
||||||
|
'#cols' => '80',
|
||||||
|
'#rows' => '20',
|
||||||
|
'#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
||||||
|
);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates action_send_email_action() form submissions.
|
||||||
|
*/
|
||||||
|
function action_send_email_action_validate($form, $form_state) {
|
||||||
|
$form_values = $form_state['values'];
|
||||||
|
// Validate the configuration form.
|
||||||
|
if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
|
||||||
|
// We want the literal %author placeholder to be emphasized in the error message.
|
||||||
|
form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes action_send_email_action() form submissions.
|
||||||
|
*/
|
||||||
|
function action_send_email_action_submit($form, $form_state) {
|
||||||
|
$form_values = $form_state['values'];
|
||||||
|
// Process the HTML form to store configuration. The keyed array that
|
||||||
|
// we return will be serialized to the database.
|
||||||
|
$params = array(
|
||||||
|
'recipient' => $form_values['recipient'],
|
||||||
|
'subject' => $form_values['subject'],
|
||||||
|
'message' => $form_values['message'],
|
||||||
|
);
|
||||||
|
return $params;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends an e-mail message.
|
||||||
|
*
|
||||||
|
* @param object $entity
|
||||||
|
* An optional node entity, which will be added as $context['node'] if
|
||||||
|
* provided.
|
||||||
|
* @param array $context
|
||||||
|
* Array with the following elements:
|
||||||
|
* - 'recipient': E-mail message recipient. This will be passed through
|
||||||
|
* token_replace().
|
||||||
|
* - 'subject': The subject of the message. This will be passed through
|
||||||
|
* token_replace().
|
||||||
|
* - 'message': The message to send. This will be passed through
|
||||||
|
* token_replace().
|
||||||
|
* - Other elements will be used as the data for token replacement.
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function action_send_email_action($entity, $context) {
|
||||||
|
if (empty($context['node'])) {
|
||||||
|
$context['node'] = $entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$recipient = token_replace($context['recipient'], $context);
|
||||||
|
|
||||||
|
// If the recipient is a registered user with a language preference, use
|
||||||
|
// the recipient's preferred language. Otherwise, use the system default
|
||||||
|
// language.
|
||||||
|
$recipient_account = user_load_by_mail($recipient);
|
||||||
|
if ($recipient_account) {
|
||||||
|
$langcode = user_preferred_langcode($recipient_account);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$langcode = language_default()->langcode;
|
||||||
|
}
|
||||||
|
$params = array('context' => $context);
|
||||||
|
|
||||||
|
if (drupal_mail('system', 'action_send_email', $recipient, $langcode, $params)) {
|
||||||
|
watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the settings form for action_message_action().
|
||||||
|
*
|
||||||
|
* @see action_message_action_submit()
|
||||||
|
*/
|
||||||
|
function action_message_action_form($context) {
|
||||||
|
$form['message'] = array(
|
||||||
|
'#type' => 'textarea',
|
||||||
|
'#title' => t('Message'),
|
||||||
|
'#default_value' => isset($context['message']) ? $context['message'] : '',
|
||||||
|
'#required' => TRUE,
|
||||||
|
'#rows' => '8',
|
||||||
|
'#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
||||||
|
);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes action_message_action form submissions.
|
||||||
|
*/
|
||||||
|
function action_message_action_submit($form, $form_state) {
|
||||||
|
return array('message' => $form_state['values']['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a message to the current user's screen.
|
||||||
|
*
|
||||||
|
* @param object $entity
|
||||||
|
* An optional node entity, which will be added as $context['node'] if
|
||||||
|
* provided.
|
||||||
|
* @param array $context
|
||||||
|
* Array with the following elements:
|
||||||
|
* - 'message': The message to send. This will be passed through
|
||||||
|
* token_replace().
|
||||||
|
* - Other elements will be used as the data for token replacement in
|
||||||
|
* the message.
|
||||||
|
*
|
||||||
|
* @ingroup actions
|
||||||
|
*/
|
||||||
|
function action_message_action(&$entity, $context = array()) {
|
||||||
|
if (empty($context['node'])) {
|
||||||
|
$context['node'] = $entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$context['message'] = token_replace(filter_xss_admin($context['message']), $context);
|
||||||
|
drupal_set_message($context['message']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs the settings form for action_goto_action().
|
||||||
|
*
|
||||||
|
* @see action_goto_action_submit()
|
||||||
|
*/
|
||||||
|
function action_goto_action_form($context) {
|
||||||
|
$form['url'] = array(
|
||||||
|
'#type' => 'textfield',
|
||||||
|
'#title' => t('URL'),
|
||||||
|
'#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like @url.', array('@url' => 'http://drupal.org')),
|
||||||
|
'#default_value' => isset($context['url']) ? $context['url'] : '',
|
||||||
|
'#required' => TRUE,
|
||||||
|
);
|
||||||
|
return $form;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes action_goto_action form submissions.
|
||||||
|
*/
|
||||||
|
function action_goto_action_submit($form, $form_state) {
|
||||||
|
return array(
|
||||||
|
'url' => $form_state['values']['url']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects to a different URL.
|
||||||
|
*
|
||||||
|
* Action functions are declared by modules by implementing hook_action_info().
|
||||||
|
* Modules can cause action functions to run by calling actions_do().
|
||||||
|
*
|
||||||
|
* @param object $entity
|
||||||
|
* An optional node entity, which will be added as $context['node'] if
|
||||||
|
* provided.
|
||||||
|
* @param array $context
|
||||||
|
* Array with the following elements:
|
||||||
|
* - 'url': URL to redirect to. This will be passed through
|
||||||
|
* token_replace().
|
||||||
|
* - Other elements will be used as the data for token replacement.
|
||||||
|
*
|
||||||
|
* @ingroup actions.
|
||||||
|
*/
|
||||||
|
function action_goto_action($entity, $context) {
|
||||||
|
drupal_goto(token_replace($context['url'], $context));
|
||||||
|
}
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* Definition of Drupal\system\Tests\Actions\ConfigurationTest.
|
* Definition of Drupal\action\Tests\ConfigurationTest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Drupal\system\Tests\Actions;
|
namespace Drupal\action\Tests;
|
||||||
|
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
|
@ -13,11 +13,19 @@ use Drupal\simpletest\WebTestBase;
|
||||||
* Actions configuration.
|
* Actions configuration.
|
||||||
*/
|
*/
|
||||||
class ConfigurationTest extends WebTestBase {
|
class ConfigurationTest extends WebTestBase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modules to enable.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $modules = array('action');
|
||||||
|
|
||||||
public static function getInfo() {
|
public static function getInfo() {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'Actions configuration',
|
'name' => 'Actions configuration',
|
||||||
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
|
'description' => 'Tests complex actions configuration by adding, editing, and deleting a complex action.',
|
||||||
'group' => 'Actions',
|
'group' => 'Action',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,15 +40,15 @@ class ConfigurationTest extends WebTestBase {
|
||||||
|
|
||||||
// Make a POST request to admin/config/system/actions/manage.
|
// Make a POST request to admin/config/system/actions/manage.
|
||||||
$edit = array();
|
$edit = array();
|
||||||
$edit['action'] = drupal_hash_base64('system_goto_action');
|
$edit['action'] = drupal_hash_base64('action_goto_action');
|
||||||
$this->drupalPost('admin/config/system/actions/manage', $edit, t('Create'));
|
$this->drupalPost('admin/config/system/actions/manage', $edit, t('Create'));
|
||||||
|
|
||||||
// Make a POST request to the individual action configuration page.
|
// Make a POST request to the individual action configuration page.
|
||||||
$edit = array();
|
$edit = array();
|
||||||
$action_label = $this->randomName();
|
$action_label = $this->randomName();
|
||||||
$edit['actions_label'] = $action_label;
|
$edit['action_label'] = $action_label;
|
||||||
$edit['url'] = 'admin';
|
$edit['url'] = 'admin';
|
||||||
$this->drupalPost('admin/config/system/actions/configure/' . drupal_hash_base64('system_goto_action'), $edit, t('Save'));
|
$this->drupalPost('admin/config/system/actions/configure/' . drupal_hash_base64('action_goto_action'), $edit, t('Save'));
|
||||||
|
|
||||||
// Make sure that the new complex action was saved properly.
|
// Make sure that the new complex action was saved properly.
|
||||||
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action."));
|
$this->assertText(t('The action has been successfully saved.'), t("Make sure we get a confirmation that we've successfully saved the complex action."));
|
||||||
|
@ -52,7 +60,7 @@ class ConfigurationTest extends WebTestBase {
|
||||||
$aid = $matches[1];
|
$aid = $matches[1];
|
||||||
$edit = array();
|
$edit = array();
|
||||||
$new_action_label = $this->randomName();
|
$new_action_label = $this->randomName();
|
||||||
$edit['actions_label'] = $new_action_label;
|
$edit['action_label'] = $new_action_label;
|
||||||
$edit['url'] = 'admin';
|
$edit['url'] = 'admin';
|
||||||
$this->drupalPost(NULL, $edit, t('Save'));
|
$this->drupalPost(NULL, $edit, t('Save'));
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* Definition of Drupal\system\Tests\Actions\LoopTest.
|
* Definition of Drupal\action\Tests\LoopTest.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace Drupal\system\Tests\Actions;
|
namespace Drupal\action\Tests;
|
||||||
|
|
||||||
use Drupal\simpletest\WebTestBase;
|
use Drupal\simpletest\WebTestBase;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ class LoopTest extends WebTestBase {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
public static $modules = array('dblog', 'actions_loop_test');
|
public static $modules = array('dblog', 'action_loop_test');
|
||||||
|
|
||||||
protected $aid;
|
protected $aid;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ class LoopTest extends WebTestBase {
|
||||||
return array(
|
return array(
|
||||||
'name' => 'Actions executing in a potentially infinite loop',
|
'name' => 'Actions executing in a potentially infinite loop',
|
||||||
'description' => 'Tests actions executing in a loop, and makes sure they abort properly.',
|
'description' => 'Tests actions executing in a loop, and makes sure they abort properly.',
|
||||||
'group' => 'Actions',
|
'group' => 'Action',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ class LoopTest extends WebTestBase {
|
||||||
$user = $this->drupalCreateUser(array('administer actions'));
|
$user = $this->drupalCreateUser(array('administer actions'));
|
||||||
$this->drupalLogin($user);
|
$this->drupalLogin($user);
|
||||||
|
|
||||||
$info = actions_loop_test_action_info();
|
$info = action_loop_test_action_info();
|
||||||
$this->aid = actions_save('actions_loop_test_log', $info['actions_loop_test_log']['type'], array(), $info['actions_loop_test_log']['label']);
|
$this->aid = action_save('action_loop_test_log', $info['action_loop_test_log']['type'], array(), $info['action_loop_test_log']['label']);
|
||||||
|
|
||||||
// Delete any existing watchdog messages to clear the plethora of
|
// Delete any existing watchdog messages to clear the plethora of
|
||||||
// "Action added" messages from when Drupal was installed.
|
// "Action added" messages from when Drupal was installed.
|
||||||
|
@ -48,25 +48,25 @@ class LoopTest extends WebTestBase {
|
||||||
// recursion level should be kept low enough to prevent the xdebug
|
// recursion level should be kept low enough to prevent the xdebug
|
||||||
// infinite recursion protection mechanism from aborting the request.
|
// infinite recursion protection mechanism from aborting the request.
|
||||||
// See http://drupal.org/node/587634.
|
// See http://drupal.org/node/587634.
|
||||||
variable_set('actions_max_stack', 7);
|
variable_set('action_max_stack', 7);
|
||||||
$this->triggerActions();
|
$this->triggerActions();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an infinite loop by causing a watchdog message to be set,
|
* Create an infinite loop by causing a watchdog message to be set,
|
||||||
* which causes the actions to be triggered again, up to actions_max_stack
|
* which causes the actions to be triggered again, up to action_max_stack
|
||||||
* times.
|
* times.
|
||||||
*/
|
*/
|
||||||
protected function triggerActions() {
|
protected function triggerActions() {
|
||||||
$this->drupalGet('<front>', array('query' => array('trigger_actions_on_watchdog' => $this->aid)));
|
$this->drupalGet('<front>', array('query' => array('trigger_action_on_watchdog' => $this->aid)));
|
||||||
$expected = array();
|
$expected = array();
|
||||||
$expected[] = 'Triggering action loop';
|
$expected[] = 'Triggering action loop';
|
||||||
for ($i = 1; $i <= variable_get('actions_max_stack', 35); $i++) {
|
for ($i = 1; $i <= variable_get('action_max_stack', 35); $i++) {
|
||||||
$expected[] = "Test log #$i";
|
$expected[] = "Test log #$i";
|
||||||
}
|
}
|
||||||
$expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
|
$expected[] = 'Stack overflow: too many calls to actions_do(). Aborting to prevent infinite recursion.';
|
||||||
|
|
||||||
$result = db_query("SELECT message FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY wid");
|
$result = db_query("SELECT message FROM {watchdog} WHERE type = 'action_loop_test' OR type = 'action' ORDER BY wid");
|
||||||
$loop_started = FALSE;
|
$loop_started = FALSE;
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$expected_message = array_shift($expected);
|
$expected_message = array_shift($expected);
|
|
@ -1,6 +1,7 @@
|
||||||
name = Actions loop test
|
name = Action loop test
|
||||||
description = Support module for action loop testing.
|
description = Support module for action loop testing.
|
||||||
package = Testing
|
package = Testing
|
||||||
version = VERSION
|
version = VERSION
|
||||||
core = 8.x
|
core = 8.x
|
||||||
hidden = TRUE
|
hidden = TRUE
|
||||||
|
dependencies[] = action
|
|
@ -3,9 +3,9 @@
|
||||||
/**
|
/**
|
||||||
* Implements hook_install().
|
* Implements hook_install().
|
||||||
*/
|
*/
|
||||||
function actions_loop_test_install() {
|
function action_loop_test_install() {
|
||||||
db_update('system')
|
db_update('system')
|
||||||
->fields(array('weight' => 1))
|
->fields(array('weight' => 1))
|
||||||
->condition('name', 'actions_loop_test')
|
->condition('name', 'action_loop_test')
|
||||||
->execute();
|
->execute();
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@
|
||||||
/**
|
/**
|
||||||
* Implements hook_watchdog().
|
* Implements hook_watchdog().
|
||||||
*/
|
*/
|
||||||
function actions_loop_test_watchdog(array $log_entry) {
|
function action_loop_test_watchdog(array $log_entry) {
|
||||||
// If the triggering actions are not explicitly enabled, abort.
|
// If the triggering actions are not explicitly enabled, abort.
|
||||||
if (empty($_GET['trigger_actions_on_watchdog'])) {
|
if (empty($_GET['trigger_action_on_watchdog'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We can pass in any applicable information in $context. There isn't much in
|
// We can pass in any applicable information in $context. There isn't much in
|
||||||
|
@ -15,25 +15,25 @@ function actions_loop_test_watchdog(array $log_entry) {
|
||||||
);
|
);
|
||||||
// Fire the actions on the associated object ($log_entry) and the context
|
// Fire the actions on the associated object ($log_entry) and the context
|
||||||
// variable.
|
// variable.
|
||||||
$aids = (array) $_GET['trigger_actions_on_watchdog'];
|
$aids = (array) $_GET['trigger_action_on_watchdog'];
|
||||||
actions_do($aids, $log_entry, $context);
|
actions_do($aids, $log_entry, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_init().
|
* Implements hook_init().
|
||||||
*/
|
*/
|
||||||
function actions_loop_test_init() {
|
function action_loop_test_init() {
|
||||||
if (!empty($_GET['trigger_actions_on_watchdog'])) {
|
if (!empty($_GET['trigger_action_on_watchdog'])) {
|
||||||
watchdog_skip_semaphore('actions_loop_test', 'Triggering action loop');
|
watchdog_skip_semaphore('action_loop_test', 'Triggering action loop');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_action_info().
|
* Implements hook_action_info().
|
||||||
*/
|
*/
|
||||||
function actions_loop_test_action_info() {
|
function action_loop_test_action_info() {
|
||||||
return array(
|
return array(
|
||||||
'actions_loop_test_log' => array(
|
'action_loop_test_log' => array(
|
||||||
'label' => t('Write a message to the log.'),
|
'label' => t('Write a message to the log.'),
|
||||||
'type' => 'system',
|
'type' => 'system',
|
||||||
'configurable' => FALSE,
|
'configurable' => FALSE,
|
||||||
|
@ -45,10 +45,10 @@ function actions_loop_test_action_info() {
|
||||||
/**
|
/**
|
||||||
* Write a message to the log.
|
* Write a message to the log.
|
||||||
*/
|
*/
|
||||||
function actions_loop_test_log() {
|
function action_loop_test_log() {
|
||||||
$count = &drupal_static(__FUNCTION__, 0);
|
$count = &drupal_static(__FUNCTION__, 0);
|
||||||
$count++;
|
$count++;
|
||||||
watchdog_skip_semaphore('actions_loop_test', "Test log #$count");
|
watchdog_skip_semaphore('action_loop_test', "Test log #$count");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -2834,281 +2834,6 @@ function system_add_date_formats_form_submit($form, &$form_state) {
|
||||||
$form_state['redirect'] = 'admin/config/regional/date-time/formats';
|
$form_state['redirect'] = 'admin/config/regional/date-time/formats';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Menu callback; Displays an overview of available and configured actions.
|
|
||||||
*/
|
|
||||||
function system_actions_manage() {
|
|
||||||
actions_synchronize();
|
|
||||||
$actions = actions_list();
|
|
||||||
$actions_map = actions_actions_map($actions);
|
|
||||||
$options = array();
|
|
||||||
$unconfigurable = array();
|
|
||||||
|
|
||||||
foreach ($actions_map as $key => $array) {
|
|
||||||
if ($array['configurable']) {
|
|
||||||
$options[$key] = $array['label'] . '...';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$unconfigurable[] = $array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$row = array();
|
|
||||||
$instances_present = db_query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
|
|
||||||
$header = array(
|
|
||||||
array('data' => t('Action type'), 'field' => 'type'),
|
|
||||||
array('data' => t('Label'), 'field' => 'label'),
|
|
||||||
array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
|
|
||||||
);
|
|
||||||
$query = db_select('actions')
|
|
||||||
->extend('Drupal\Core\Database\Query\PagerSelectExtender')
|
|
||||||
->extend('Drupal\Core\Database\Query\TableSortExtender');
|
|
||||||
$result = $query
|
|
||||||
->fields('actions')
|
|
||||||
->limit(50)
|
|
||||||
->orderByHeader($header)
|
|
||||||
->execute();
|
|
||||||
|
|
||||||
foreach ($result as $action) {
|
|
||||||
$row[] = array(
|
|
||||||
array('data' => $action->type),
|
|
||||||
array('data' => check_plain($action->label)),
|
|
||||||
array('data' => $action->parameters ? l(t('configure'), "admin/config/system/actions/configure/$action->aid") : ''),
|
|
||||||
array('data' => $action->parameters ? l(t('delete'), "admin/config/system/actions/delete/$action->aid") : '')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($row) {
|
|
||||||
$pager = theme('pager');
|
|
||||||
if (!empty($pager)) {
|
|
||||||
$row[] = array(array('data' => $pager, 'colspan' => '3'));
|
|
||||||
}
|
|
||||||
$build['system_actions_header'] = array('#markup' => '<h3>' . t('Available actions:') . '</h3>');
|
|
||||||
$build['system_actions_table'] = array('#markup' => theme('table', array('header' => $header, 'rows' => $row)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($actions_map) {
|
|
||||||
$build['system_actions_manage_form'] = drupal_get_form('system_actions_manage_form', $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $build;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Define the form for the actions overview page.
|
|
||||||
*
|
|
||||||
* @param $form_state
|
|
||||||
* An associative array containing the current state of the form; not used.
|
|
||||||
* @param $options
|
|
||||||
* An array of configurable actions.
|
|
||||||
* @return
|
|
||||||
* Form definition.
|
|
||||||
*
|
|
||||||
* @ingroup forms
|
|
||||||
* @see system_actions_manage_form_submit()
|
|
||||||
*/
|
|
||||||
function system_actions_manage_form($form, &$form_state, $options = array()) {
|
|
||||||
$form['parent'] = array(
|
|
||||||
'#type' => 'fieldset',
|
|
||||||
'#title' => t('Create an advanced action'),
|
|
||||||
'#attributes' => array('class' => array('container-inline')),
|
|
||||||
);
|
|
||||||
$form['parent']['action'] = array(
|
|
||||||
'#type' => 'select',
|
|
||||||
'#title' => t('Action'),
|
|
||||||
'#title_display' => 'invisible',
|
|
||||||
'#options' => $options,
|
|
||||||
'#empty_option' => t('Choose an advanced action'),
|
|
||||||
);
|
|
||||||
$form['parent']['actions'] = array('#type' => 'actions');
|
|
||||||
$form['parent']['actions']['submit'] = array(
|
|
||||||
'#type' => 'submit',
|
|
||||||
'#value' => t('Create'),
|
|
||||||
);
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process system_actions_manage form submissions.
|
|
||||||
*
|
|
||||||
* @see system_actions_manage_form()
|
|
||||||
*/
|
|
||||||
function system_actions_manage_form_submit($form, &$form_state) {
|
|
||||||
if ($form_state['values']['action']) {
|
|
||||||
$form_state['redirect'] = 'admin/config/system/actions/configure/' . $form_state['values']['action'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Menu callback; Creates the form for configuration of a single action.
|
|
||||||
*
|
|
||||||
* We provide the "Description" field. The rest of the form is provided by the
|
|
||||||
* action. We then provide the Save button. Because we are combining unknown
|
|
||||||
* form elements with the action configuration form, we use an 'actions_' prefix
|
|
||||||
* on our elements.
|
|
||||||
*
|
|
||||||
* @param $action
|
|
||||||
* Hash of an action ID or an integer. If it is a hash, we are
|
|
||||||
* creating a new instance. If it is an integer, we are editing an existing
|
|
||||||
* instance.
|
|
||||||
* @return
|
|
||||||
* A form definition.
|
|
||||||
*
|
|
||||||
* @see system_actions_configure_validate()
|
|
||||||
* @see system_actions_configure_submit()
|
|
||||||
*/
|
|
||||||
function system_actions_configure($form, &$form_state, $action = NULL) {
|
|
||||||
if ($action === NULL) {
|
|
||||||
drupal_goto('admin/config/system/actions');
|
|
||||||
}
|
|
||||||
|
|
||||||
$actions_map = actions_actions_map(actions_list());
|
|
||||||
$edit = array();
|
|
||||||
|
|
||||||
// Numeric action denotes saved instance of a configurable action.
|
|
||||||
if (is_numeric($action)) {
|
|
||||||
$aid = $action;
|
|
||||||
// Load stored parameter values from database.
|
|
||||||
$data = db_query("SELECT * FROM {actions} WHERE aid = :aid", array(':aid' => $aid))->fetch();
|
|
||||||
$edit['actions_label'] = $data->label;
|
|
||||||
$edit['actions_type'] = $data->type;
|
|
||||||
$function = $data->callback;
|
|
||||||
$action = drupal_hash_base64($data->callback);
|
|
||||||
$params = unserialize($data->parameters);
|
|
||||||
if ($params) {
|
|
||||||
foreach ($params as $name => $val) {
|
|
||||||
$edit[$name] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Otherwise, we are creating a new action instance.
|
|
||||||
else {
|
|
||||||
$function = $actions_map[$action]['callback'];
|
|
||||||
$edit['actions_label'] = $actions_map[$action]['label'];
|
|
||||||
$edit['actions_type'] = $actions_map[$action]['type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$form['actions_label'] = array(
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('Label'),
|
|
||||||
'#default_value' => $edit['actions_label'],
|
|
||||||
'#maxlength' => '255',
|
|
||||||
'#description' => t('A unique label for this advanced action. This label will be displayed in the interface of modules that integrate with actions.'),
|
|
||||||
'#weight' => -10
|
|
||||||
);
|
|
||||||
$action_form = $function . '_form';
|
|
||||||
$form = array_merge($form, $action_form($edit));
|
|
||||||
$form['actions_type'] = array(
|
|
||||||
'#type' => 'value',
|
|
||||||
'#value' => $edit['actions_type'],
|
|
||||||
);
|
|
||||||
$form['actions_action'] = array(
|
|
||||||
'#type' => 'hidden',
|
|
||||||
'#value' => $action,
|
|
||||||
);
|
|
||||||
// $aid is set when configuring an existing action instance.
|
|
||||||
if (isset($aid)) {
|
|
||||||
$form['actions_aid'] = array(
|
|
||||||
'#type' => 'hidden',
|
|
||||||
'#value' => $aid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
$form['actions_configured'] = array(
|
|
||||||
'#type' => 'hidden',
|
|
||||||
'#value' => '1',
|
|
||||||
);
|
|
||||||
$form['actions'] = array('#type' => 'actions');
|
|
||||||
$form['actions']['submit'] = array(
|
|
||||||
'#type' => 'submit',
|
|
||||||
'#value' => t('Save'),
|
|
||||||
'#weight' => 13
|
|
||||||
);
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate system_actions_configure() form submissions.
|
|
||||||
*/
|
|
||||||
function system_actions_configure_validate($form, &$form_state) {
|
|
||||||
$function = actions_function_lookup($form_state['values']['actions_action']) . '_validate';
|
|
||||||
// Hand off validation to the action.
|
|
||||||
if (function_exists($function)) {
|
|
||||||
$function($form, $form_state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process system_actions_configure() form submissions.
|
|
||||||
*/
|
|
||||||
function system_actions_configure_submit($form, &$form_state) {
|
|
||||||
$function = actions_function_lookup($form_state['values']['actions_action']);
|
|
||||||
$submit_function = $function . '_submit';
|
|
||||||
|
|
||||||
// Action will return keyed array of values to store.
|
|
||||||
$params = $submit_function($form, $form_state);
|
|
||||||
$aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
|
|
||||||
|
|
||||||
actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_label'], $aid);
|
|
||||||
drupal_set_message(t('The action has been successfully saved.'));
|
|
||||||
|
|
||||||
$form_state['redirect'] = 'admin/config/system/actions/manage';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create the form for confirmation of deleting an action.
|
|
||||||
*
|
|
||||||
* @see system_actions_delete_form_submit()
|
|
||||||
* @ingroup forms
|
|
||||||
*/
|
|
||||||
function system_actions_delete_form($form, &$form_state, $action) {
|
|
||||||
$form['aid'] = array(
|
|
||||||
'#type' => 'hidden',
|
|
||||||
'#value' => $action->aid,
|
|
||||||
);
|
|
||||||
return confirm_form($form,
|
|
||||||
t('Are you sure you want to delete the action %action?', array('%action' => $action->label)),
|
|
||||||
'admin/config/system/actions/manage',
|
|
||||||
t('This cannot be undone.'),
|
|
||||||
t('Delete'),
|
|
||||||
t('Cancel')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process system_actions_delete form submissions.
|
|
||||||
*
|
|
||||||
* Post-deletion operations for action deletion.
|
|
||||||
*/
|
|
||||||
function system_actions_delete_form_submit($form, &$form_state) {
|
|
||||||
$aid = $form_state['values']['aid'];
|
|
||||||
$action = actions_load($aid);
|
|
||||||
actions_delete($aid);
|
|
||||||
watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $action->label));
|
|
||||||
drupal_set_message(t('Action %action was deleted', array('%action' => $action->label)));
|
|
||||||
$form_state['redirect'] = 'admin/config/system/actions/manage';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Post-deletion operations for deleting action orphans.
|
|
||||||
*
|
|
||||||
* @param $orphaned
|
|
||||||
* An array of orphaned actions.
|
|
||||||
*/
|
|
||||||
function system_action_delete_orphans_post($orphaned) {
|
|
||||||
foreach ($orphaned as $callback) {
|
|
||||||
drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove actions that are in the database but not supported by any enabled module.
|
|
||||||
*/
|
|
||||||
function system_actions_remove_orphans() {
|
|
||||||
actions_synchronize(TRUE);
|
|
||||||
drupal_goto('admin/config/system/actions/manage');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display edit date format links for each language.
|
* Display edit date format links for each language.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3169,94 +3169,6 @@ function hook_file_mimetype_mapping_alter(&$mapping) {
|
||||||
$mapping['extensions']['ogg'] = 189;
|
$mapping['extensions']['ogg'] = 189;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Declares information about actions.
|
|
||||||
*
|
|
||||||
* Any module can define actions, and then call actions_do() to make those
|
|
||||||
* actions happen in response to events.
|
|
||||||
*
|
|
||||||
* An action consists of two or three parts:
|
|
||||||
* - an action definition (returned by this hook)
|
|
||||||
* - a function which performs the action (which by convention is named
|
|
||||||
* MODULE_description-of-function_action)
|
|
||||||
* - an optional form definition function that defines a configuration form
|
|
||||||
* (which has the name of the action function with '_form' appended to it.)
|
|
||||||
*
|
|
||||||
* The action function takes two to four arguments, which come from the input
|
|
||||||
* arguments to actions_do().
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* An associative array of action descriptions. The keys of the array
|
|
||||||
* are the names of the action functions, and each corresponding value
|
|
||||||
* is an associative array with the following key-value pairs:
|
|
||||||
* - 'type': The type of object this action acts upon. Core actions have types
|
|
||||||
* 'node', 'user', 'comment', and 'system'.
|
|
||||||
* - 'label': The human-readable name of the action, which should be passed
|
|
||||||
* through the t() function for translation.
|
|
||||||
* - 'configurable': If FALSE, then the action doesn't require any extra
|
|
||||||
* configuration. If TRUE, then your module must define a form function with
|
|
||||||
* the same name as the action function with '_form' appended (e.g., the
|
|
||||||
* form for 'node_assign_owner_action' is 'node_assign_owner_action_form'.)
|
|
||||||
* This function takes $context as its only parameter, and is paired with
|
|
||||||
* the usual _submit function, and possibly a _validate function.
|
|
||||||
* - 'triggers': An array of the events (that is, hooks) that can trigger this
|
|
||||||
* action. For example: array('node_insert', 'user_update'). You can also
|
|
||||||
* declare support for any trigger by returning array('any') for this value.
|
|
||||||
* - 'behavior': (optional) A machine-readable array of behaviors of this
|
|
||||||
* action, used to signal additionally required actions that may need to be
|
|
||||||
* triggered. Modules that are processing actions should take special care
|
|
||||||
* for the "presave" hook, in which case a dependent "save" action should
|
|
||||||
* NOT be invoked.
|
|
||||||
*
|
|
||||||
* @ingroup actions
|
|
||||||
*/
|
|
||||||
function hook_action_info() {
|
|
||||||
return array(
|
|
||||||
'comment_unpublish_action' => array(
|
|
||||||
'type' => 'comment',
|
|
||||||
'label' => t('Unpublish comment'),
|
|
||||||
'configurable' => FALSE,
|
|
||||||
'behavior' => array('changes_property'),
|
|
||||||
'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
|
|
||||||
),
|
|
||||||
'comment_unpublish_by_keyword_action' => array(
|
|
||||||
'type' => 'comment',
|
|
||||||
'label' => t('Unpublish comment containing keyword(s)'),
|
|
||||||
'configurable' => TRUE,
|
|
||||||
'behavior' => array('changes_property'),
|
|
||||||
'triggers' => array('comment_presave', 'comment_insert', 'comment_update'),
|
|
||||||
),
|
|
||||||
'comment_save_action' => array(
|
|
||||||
'type' => 'comment',
|
|
||||||
'label' => t('Save comment'),
|
|
||||||
'configurable' => FALSE,
|
|
||||||
'triggers' => array('comment_insert', 'comment_update'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Executes code after an action is deleted.
|
|
||||||
*
|
|
||||||
* @param $aid
|
|
||||||
* The action ID.
|
|
||||||
*/
|
|
||||||
function hook_actions_delete($aid) {
|
|
||||||
db_delete('actions_assignments')
|
|
||||||
->condition('aid', $aid)
|
|
||||||
->execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alters the actions declared by another module.
|
|
||||||
*
|
|
||||||
* Called by actions_list() to allow modules to alter the return values from
|
|
||||||
* implementations of hook_action_info().
|
|
||||||
*/
|
|
||||||
function hook_action_info_alter(&$actions) {
|
|
||||||
$actions['node_unpublish_action']['label'] = t('Unpublish and remove from public view.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare archivers to the system.
|
* Declare archivers to the system.
|
||||||
*
|
*
|
||||||
|
|
|
@ -552,47 +552,6 @@ function system_schema() {
|
||||||
'primary key' => array('name'),
|
'primary key' => array('name'),
|
||||||
);
|
);
|
||||||
|
|
||||||
$schema['actions'] = array(
|
|
||||||
'description' => 'Stores action information.',
|
|
||||||
'fields' => array(
|
|
||||||
'aid' => array(
|
|
||||||
'description' => 'Primary Key: Unique actions ID.',
|
|
||||||
'type' => 'varchar',
|
|
||||||
'length' => 255,
|
|
||||||
'not null' => TRUE,
|
|
||||||
'default' => '0',
|
|
||||||
),
|
|
||||||
'type' => array(
|
|
||||||
'description' => 'The object that that action acts on (node, user, comment, system or custom types.)',
|
|
||||||
'type' => 'varchar',
|
|
||||||
'length' => 32,
|
|
||||||
'not null' => TRUE,
|
|
||||||
'default' => '',
|
|
||||||
),
|
|
||||||
'callback' => array(
|
|
||||||
'description' => 'The callback function that executes when the action runs.',
|
|
||||||
'type' => 'varchar',
|
|
||||||
'length' => 255,
|
|
||||||
'not null' => TRUE,
|
|
||||||
'default' => '',
|
|
||||||
),
|
|
||||||
'parameters' => array(
|
|
||||||
'description' => 'Parameters to be passed to the callback function.',
|
|
||||||
'type' => 'blob',
|
|
||||||
'not null' => TRUE,
|
|
||||||
'size' => 'big',
|
|
||||||
),
|
|
||||||
'label' => array(
|
|
||||||
'description' => 'Label of the action.',
|
|
||||||
'type' => 'varchar',
|
|
||||||
'length' => 255,
|
|
||||||
'not null' => TRUE,
|
|
||||||
'default' => '0',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'primary key' => array('aid'),
|
|
||||||
);
|
|
||||||
|
|
||||||
$schema['batch'] = array(
|
$schema['batch'] = array(
|
||||||
'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
|
'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
|
@ -1971,12 +1930,14 @@ function system_update_8020() {
|
||||||
->execute();
|
->execute();
|
||||||
// Rename {blocked_ips} table into {ban_ip}.
|
// Rename {blocked_ips} table into {ban_ip}.
|
||||||
db_rename_table('blocked_ips', 'ban_ip');
|
db_rename_table('blocked_ips', 'ban_ip');
|
||||||
// Rename the action.
|
// Rename all references to the action callback.
|
||||||
db_update('actions')
|
db_update('actions')
|
||||||
->fields(array(
|
->fields(array('callback' => 'ban_ip_action'))
|
||||||
'aid' => 'ban_ip_action',
|
->condition('callback', 'system_block_ip_action')
|
||||||
'callback' => 'ban_ip_action',
|
->execute();
|
||||||
))
|
// Rename the action's aid.
|
||||||
|
db_update('actions')
|
||||||
|
->fields(array('aid' => 'ban_ip_action'))
|
||||||
->condition('aid', 'system_block_ip_action')
|
->condition('aid', 'system_block_ip_action')
|
||||||
->execute();
|
->execute();
|
||||||
// Enable the new Ban module.
|
// Enable the new Ban module.
|
||||||
|
@ -1988,6 +1949,32 @@ function system_update_8020() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable the Actions module.
|
||||||
|
*/
|
||||||
|
function system_update_8021() {
|
||||||
|
// Enable the module without re-installing the schema.
|
||||||
|
update_module_enable(array('action'));
|
||||||
|
// Rename former System module actions.
|
||||||
|
$map = array(
|
||||||
|
'system_message_action' => 'action_message_action',
|
||||||
|
'system_send_email_action' => 'action_send_email_action',
|
||||||
|
'system_goto_action' => 'action_goto_action',
|
||||||
|
);
|
||||||
|
foreach ($map as $old => $new) {
|
||||||
|
// Rename all references to the action callback.
|
||||||
|
db_update('actions')
|
||||||
|
->fields(array('callback' => $new))
|
||||||
|
->condition('callback', $old)
|
||||||
|
->execute();
|
||||||
|
// Rename the action's aid.
|
||||||
|
db_update('actions')
|
||||||
|
->fields(array('aid' => $new))
|
||||||
|
->condition('aid', $old)
|
||||||
|
->execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @} End of "defgroup updates-7.x-to-8.x".
|
* @} End of "defgroup updates-7.x-to-8.x".
|
||||||
* The next series of updates should start at 9000.
|
* The next series of updates should start at 9000.
|
||||||
|
|
|
@ -89,8 +89,6 @@ function system_help($path, $arg) {
|
||||||
$output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis. The System module manages this task by making use of a system cron job. You can verify the status of cron tasks by visiting the <a href="@status">Status report page</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>. You can set up cron job by visiting <a href="@cron">Cron configuration</a> page', array('@status' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron', '@cron' => url('admin/config/system/cron'))) . '</dd>';
|
$output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis. The System module manages this task by making use of a system cron job. You can verify the status of cron tasks by visiting the <a href="@status">Status report page</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>. You can set up cron job by visiting <a href="@cron">Cron configuration</a> page', array('@status' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron', '@cron' => url('admin/config/system/cron'))) . '</dd>';
|
||||||
$output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
|
$output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
|
||||||
$output .= '<dd>' . t('The System module also handles basic configuration options for your site, including <a href="@date-time-settings">Date and time settings</a>, <a href="@file-system">File system settings</a>, <a href="@site-info">Site name and other information</a>, and a <a href="@maintenance-mode">Maintenance mode</a> for taking your site temporarily offline.', array('@date-time-settings' => url('admin/config/regional/date-time'), '@file-system' => url('admin/config/media/file-system'), '@site-info' => url('admin/config/system/site-information'), '@maintenance-mode' => url('admin/config/development/maintenance'))) . '</dd>';
|
$output .= '<dd>' . t('The System module also handles basic configuration options for your site, including <a href="@date-time-settings">Date and time settings</a>, <a href="@file-system">File system settings</a>, <a href="@site-info">Site name and other information</a>, and a <a href="@maintenance-mode">Maintenance mode</a> for taking your site temporarily offline.', array('@date-time-settings' => url('admin/config/regional/date-time'), '@file-system' => url('admin/config/media/file-system'), '@site-info' => url('admin/config/system/site-information'), '@maintenance-mode' => url('admin/config/development/maintenance'))) . '</dd>';
|
||||||
$output .= '<dt>' . t('Configuring actions') . '</dt>';
|
|
||||||
$output .= '<dd>' . t('Actions are individual tasks that the system can do, such as unpublishing a piece of content or banning a user. Other modules can fire these actions when certain system events happen; for example, when a new post is added or when a user logs in. Modules may also provide additional actions. Visit the <a href="@actions">Actions page</a> to configure actions.', array('@actions' => url('admin/config/system/actions'))) . '</dd>';
|
|
||||||
$output .= '</dl>';
|
$output .= '</dl>';
|
||||||
return $output;
|
return $output;
|
||||||
case 'admin/index':
|
case 'admin/index':
|
||||||
|
@ -131,13 +129,6 @@ function system_help($path, $arg) {
|
||||||
return '<p>' . t('Use maintenance mode when making major updates, particularly if the updates could disrupt visitors or the update process. Examples include upgrading, importing or exporting content, modifying a theme, modifying content types, and making backups.') . '</p>';
|
return '<p>' . t('Use maintenance mode when making major updates, particularly if the updates could disrupt visitors or the update process. Examples include upgrading, importing or exporting content, modifying a theme, modifying content types, and making backups.') . '</p>';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'admin/config/system/actions':
|
|
||||||
case 'admin/config/system/actions/manage':
|
|
||||||
$output = '';
|
|
||||||
$output .= '<p>' . t('There are two types of actions: simple and advanced. Simple actions do not require any additional configuration and are listed here automatically. Advanced actions need to be created and configured before they can be used because they have options that need to be specified; for example, sending an e-mail to a specified address or unpublishing content containing certain words. To create an advanced action, select the action from the drop-down list in the advanced action section below and click the <em>Create</em> button.') . '</p>';
|
|
||||||
return $output;
|
|
||||||
case 'admin/config/system/actions/configure':
|
|
||||||
return t('An advanced action offers additional configuration options which may be filled out below. Changing the <em>Description</em> field is recommended in order to better identify the precise action taking place.');
|
|
||||||
case 'admin/reports/status':
|
case 'admin/reports/status':
|
||||||
return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues. Before filing a support request, ensure that your web server meets the <a href=\"@system-requirements\">system requirements.</a>", array('@system-requirements' => 'http://drupal.org/requirements')) . '</p>';
|
return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on drupal.org's support forums and project issue queues. Before filing a support request, ensure that your web server meets the <a href=\"@system-requirements\">system requirements.</a>", array('@system-requirements' => 'http://drupal.org/requirements')) . '</p>';
|
||||||
}
|
}
|
||||||
|
@ -225,9 +216,6 @@ function system_permission() {
|
||||||
'title' => t('Administer software updates'),
|
'title' => t('Administer software updates'),
|
||||||
'restrict access' => TRUE,
|
'restrict access' => TRUE,
|
||||||
),
|
),
|
||||||
'administer actions' => array(
|
|
||||||
'title' => t('Administer actions'),
|
|
||||||
),
|
|
||||||
'access administration pages' => array(
|
'access administration pages' => array(
|
||||||
'title' => t('Use the administration pages and help'),
|
'title' => t('Use the administration pages and help'),
|
||||||
),
|
),
|
||||||
|
@ -960,44 +948,6 @@ function system_menu() {
|
||||||
'access arguments' => array('access administration pages'),
|
'access arguments' => array('access administration pages'),
|
||||||
'file' => 'system.admin.inc',
|
'file' => 'system.admin.inc',
|
||||||
);
|
);
|
||||||
$items['admin/config/system/actions'] = array(
|
|
||||||
'title' => 'Actions',
|
|
||||||
'description' => 'Manage the actions defined for your site.',
|
|
||||||
'access arguments' => array('administer actions'),
|
|
||||||
'page callback' => 'system_actions_manage',
|
|
||||||
'file' => 'system.admin.inc',
|
|
||||||
);
|
|
||||||
$items['admin/config/system/actions/manage'] = array(
|
|
||||||
'title' => 'Manage actions',
|
|
||||||
'description' => 'Manage the actions defined for your site.',
|
|
||||||
'page callback' => 'system_actions_manage',
|
|
||||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
|
||||||
'weight' => -2,
|
|
||||||
'file' => 'system.admin.inc',
|
|
||||||
);
|
|
||||||
$items['admin/config/system/actions/configure'] = array(
|
|
||||||
'title' => 'Configure an advanced action',
|
|
||||||
'page callback' => 'drupal_get_form',
|
|
||||||
'page arguments' => array('system_actions_configure'),
|
|
||||||
'access arguments' => array('administer actions'),
|
|
||||||
'type' => MENU_VISIBLE_IN_BREADCRUMB,
|
|
||||||
'file' => 'system.admin.inc',
|
|
||||||
);
|
|
||||||
$items['admin/config/system/actions/delete/%actions'] = array(
|
|
||||||
'title' => 'Delete action',
|
|
||||||
'description' => 'Delete an action.',
|
|
||||||
'page callback' => 'drupal_get_form',
|
|
||||||
'page arguments' => array('system_actions_delete_form', 5),
|
|
||||||
'access arguments' => array('administer actions'),
|
|
||||||
'file' => 'system.admin.inc',
|
|
||||||
);
|
|
||||||
$items['admin/config/system/actions/orphan'] = array(
|
|
||||||
'title' => 'Remove orphans',
|
|
||||||
'page callback' => 'system_actions_remove_orphans',
|
|
||||||
'access arguments' => array('administer actions'),
|
|
||||||
'type' => MENU_CALLBACK,
|
|
||||||
'file' => 'system.admin.inc',
|
|
||||||
);
|
|
||||||
$items['admin/config/system/site-information'] = array(
|
$items['admin/config/system/site-information'] = array(
|
||||||
'title' => 'Site information',
|
'title' => 'Site information',
|
||||||
'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.',
|
'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.',
|
||||||
|
@ -3494,155 +3444,6 @@ function system_cache_flush() {
|
||||||
function system_rebuild() {
|
function system_rebuild() {
|
||||||
// Rebuild list of date formats.
|
// Rebuild list of date formats.
|
||||||
system_date_formats_rebuild();
|
system_date_formats_rebuild();
|
||||||
// Synchronize any actions that were added or removed.
|
|
||||||
actions_synchronize();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implements hook_action_info().
|
|
||||||
*/
|
|
||||||
function system_action_info() {
|
|
||||||
return array(
|
|
||||||
'system_message_action' => array(
|
|
||||||
'type' => 'system',
|
|
||||||
'label' => t('Display a message to the user'),
|
|
||||||
'configurable' => TRUE,
|
|
||||||
'triggers' => array('any'),
|
|
||||||
),
|
|
||||||
'system_send_email_action' => array(
|
|
||||||
'type' => 'system',
|
|
||||||
'label' => t('Send e-mail'),
|
|
||||||
'configurable' => TRUE,
|
|
||||||
'triggers' => array('any'),
|
|
||||||
),
|
|
||||||
'system_goto_action' => array(
|
|
||||||
'type' => 'system',
|
|
||||||
'label' => t('Redirect to URL'),
|
|
||||||
'configurable' => TRUE,
|
|
||||||
'triggers' => array('any'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a form definition so the Send email action can be configured.
|
|
||||||
*
|
|
||||||
* @param $context
|
|
||||||
* Default values (if we are editing an existing action instance).
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* Form definition.
|
|
||||||
*
|
|
||||||
* @see system_send_email_action_validate()
|
|
||||||
* @see system_send_email_action_submit()
|
|
||||||
*/
|
|
||||||
function system_send_email_action_form($context) {
|
|
||||||
// Set default values for form.
|
|
||||||
if (!isset($context['recipient'])) {
|
|
||||||
$context['recipient'] = '';
|
|
||||||
}
|
|
||||||
if (!isset($context['subject'])) {
|
|
||||||
$context['subject'] = '';
|
|
||||||
}
|
|
||||||
if (!isset($context['message'])) {
|
|
||||||
$context['message'] = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$form['recipient'] = array(
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('Recipient'),
|
|
||||||
'#default_value' => $context['recipient'],
|
|
||||||
'#maxlength' => '254',
|
|
||||||
'#description' => t('The e-mail address to which the message should be sent OR enter [node:author:mail], [comment:author:mail], etc. if you would like to send an e-mail to the author of the original post.'),
|
|
||||||
);
|
|
||||||
$form['subject'] = array(
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('Subject'),
|
|
||||||
'#default_value' => $context['subject'],
|
|
||||||
'#maxlength' => '254',
|
|
||||||
'#description' => t('The subject of the message.'),
|
|
||||||
);
|
|
||||||
$form['message'] = array(
|
|
||||||
'#type' => 'textarea',
|
|
||||||
'#title' => t('Message'),
|
|
||||||
'#default_value' => $context['message'],
|
|
||||||
'#cols' => '80',
|
|
||||||
'#rows' => '20',
|
|
||||||
'#description' => t('The message that should be sent. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
|
||||||
);
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate system_send_email_action form submissions.
|
|
||||||
*/
|
|
||||||
function system_send_email_action_validate($form, $form_state) {
|
|
||||||
$form_values = $form_state['values'];
|
|
||||||
// Validate the configuration form.
|
|
||||||
if (!valid_email_address($form_values['recipient']) && strpos($form_values['recipient'], ':mail') === FALSE) {
|
|
||||||
// We want the literal %author placeholder to be emphasized in the error message.
|
|
||||||
form_set_error('recipient', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process system_send_email_action form submissions.
|
|
||||||
*/
|
|
||||||
function system_send_email_action_submit($form, $form_state) {
|
|
||||||
$form_values = $form_state['values'];
|
|
||||||
// Process the HTML form to store configuration. The keyed array that
|
|
||||||
// we return will be serialized to the database.
|
|
||||||
$params = array(
|
|
||||||
'recipient' => $form_values['recipient'],
|
|
||||||
'subject' => $form_values['subject'],
|
|
||||||
'message' => $form_values['message'],
|
|
||||||
);
|
|
||||||
return $params;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends an e-mail message.
|
|
||||||
*
|
|
||||||
* @param object $entity
|
|
||||||
* An optional node entity, which will be added as $context['node'] if
|
|
||||||
* provided.
|
|
||||||
* @param array $context
|
|
||||||
* Array with the following elements:
|
|
||||||
* - 'recipient': E-mail message recipient. This will be passed through
|
|
||||||
* token_replace().
|
|
||||||
* - 'subject': The subject of the message. This will be passed through
|
|
||||||
* token_replace().
|
|
||||||
* - 'message': The message to send. This will be passed through
|
|
||||||
* token_replace().
|
|
||||||
* - Other elements will be used as the data for token replacement.
|
|
||||||
*
|
|
||||||
* @ingroup actions
|
|
||||||
*/
|
|
||||||
function system_send_email_action($entity, $context) {
|
|
||||||
if (empty($context['node'])) {
|
|
||||||
$context['node'] = $entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
$recipient = token_replace($context['recipient'], $context);
|
|
||||||
|
|
||||||
// If the recipient is a registered user with a language preference, use
|
|
||||||
// the recipient's preferred language. Otherwise, use the system default
|
|
||||||
// language.
|
|
||||||
$recipient_account = user_load_by_mail($recipient);
|
|
||||||
if ($recipient_account) {
|
|
||||||
$langcode = user_preferred_langcode($recipient_account);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$langcode = language_default()->langcode;
|
|
||||||
}
|
|
||||||
$params = array('context' => $context);
|
|
||||||
|
|
||||||
if (drupal_mail('system', 'action_send_email', $recipient, $langcode, $params)) {
|
|
||||||
watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
watchdog('error', 'Unable to send email to %recipient', array('%recipient' => $recipient));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3658,83 +3459,6 @@ function system_mail($key, &$message, $params) {
|
||||||
$message['body'][] = $body;
|
$message['body'][] = $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
function system_message_action_form($context) {
|
|
||||||
$form['message'] = array(
|
|
||||||
'#type' => 'textarea',
|
|
||||||
'#title' => t('Message'),
|
|
||||||
'#default_value' => isset($context['message']) ? $context['message'] : '',
|
|
||||||
'#required' => TRUE,
|
|
||||||
'#rows' => '8',
|
|
||||||
'#description' => t('The message to be displayed to the current user. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
|
||||||
);
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function system_message_action_submit($form, $form_state) {
|
|
||||||
return array('message' => $form_state['values']['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sends a message to the current user's screen.
|
|
||||||
*
|
|
||||||
* @param object $entity
|
|
||||||
* An optional node entity, which will be added as $context['node'] if
|
|
||||||
* provided.
|
|
||||||
* @param array $context
|
|
||||||
* Array with the following elements:
|
|
||||||
* - 'message': The message to send. This will be passed through
|
|
||||||
* token_replace().
|
|
||||||
* - Other elements will be used as the data for token replacement in
|
|
||||||
* the message.
|
|
||||||
*
|
|
||||||
* @ingroup actions
|
|
||||||
*/
|
|
||||||
function system_message_action(&$entity, $context = array()) {
|
|
||||||
if (empty($context['node'])) {
|
|
||||||
$context['node'] = $entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
$context['message'] = token_replace(filter_xss_admin($context['message']), $context);
|
|
||||||
drupal_set_message($context['message']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Settings form for system_goto_action().
|
|
||||||
*/
|
|
||||||
function system_goto_action_form($context) {
|
|
||||||
$form['url'] = array(
|
|
||||||
'#type' => 'textfield',
|
|
||||||
'#title' => t('URL'),
|
|
||||||
'#description' => t('The URL to which the user should be redirected. This can be an internal URL like node/1234 or an external URL like @url.', array('@url' => 'http://drupal.org')),
|
|
||||||
'#default_value' => isset($context['url']) ? $context['url'] : '',
|
|
||||||
'#required' => TRUE,
|
|
||||||
);
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
function system_goto_action_submit($form, $form_state) {
|
|
||||||
return array(
|
|
||||||
'url' => $form_state['values']['url']
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirects to a different URL.
|
|
||||||
*
|
|
||||||
* @param $entity
|
|
||||||
* Ignored.
|
|
||||||
* @param array $context
|
|
||||||
* Array with the following elements:
|
|
||||||
* - 'url': URL to redirect to. This will be passed through
|
|
||||||
* token_replace().
|
|
||||||
* - Other elements will be used as the data for token replacement.
|
|
||||||
*
|
|
||||||
* @ingroup actions
|
|
||||||
*/
|
|
||||||
function system_goto_action($entity, $context) {
|
|
||||||
drupal_goto(token_replace($context['url'], $context));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an array of time zones and their local time&date.
|
* Generate an array of time zones and their local time&date.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue