function configuration_process_action in Configuration Management 6
Execute a single action
1 call to configuration_process_action()
- configuration_process_actions in ./
configuration.module - Move through the actions list processing one per call
File
- ./
configuration.module, line 386 - Provide a unified method for defining site configurations abstracted from their data format. Various data formats should be supported via a plugin architecture such as XML, YAML, JSON, PHP
Code
function configuration_process_action($action) {
// Get the module list of actions and identifiers
$actions =& module_invoke_all('configuration_actions');
$identifiers =& configuration_get_data('identifiers');
$action_id = $action[0];
$action_info = $actions[$action_id];
$action_context =& $action[1];
if (!isset($action_info)) {
configuration_set_error('invalid action id', array(
'!action' => $action_id,
));
return false;
}
// Replace identifiers and tokens in the action data
configuration_replace_tokens($action_context, $identifiers);
// Unlikely, but if there is an error replacing tokens
if (configuration_get_error()) {
return false;
}
// With proper data and values replaced, apply the actions build map. This is a great
// place to do any validation as well (using a #validate callback property or directly)
// TODO Implement #validate property...
if ($action_info['#build map']) {
configuration_apply_map($action_context, $action_info['#build map']);
}
if (configuration_get_error()) {
configuration_set_error('action build map', array(
'!action' => $action_id,
));
}
// Build the execute $args array. Starting with the actual form data
//if ($action_context->build_data) {
if ($action_info['#build data'] && ($matches = configuration_fetch($action_info['#build data'], $action_context))) {
$action_data = $matches[0]->item;
}
else {
$action_data = $action_context->item;
}
// Then the form state
if ($action_context->form_state) {
$action_state =& $action_context->form_state;
$action_state['values'] =& $action_data;
}
else {
$action_state = array(
'storage' => null,
'submitted' => false,
'values' => &$action_data,
);
}
// Then the params
for ($i = 0; isset($action_info['#parameters'][$i]); $i++) {
$matches = configuration_fetch($action_info['#parameters'][$i], $action_context);
// Ensure that the parameter is at least set
$params[$i] = null;
if (isset($matches[0])) {
$params[$i] = $matches[0]->item;
}
}
// Drupal Execute
configuration_drupal_execute($action_id, $action_state, $params);
// Store any form errors
if ($form_errors = form_set_error()) {
configuration_set_error('form error', $form_errors);
}
else {
if ($action_info['#success map']) {
configuration_apply_map($action_context, $action_info['#success map']);
}
// TODO Replace identifiers before running action
if (!empty($action_info['#identifiers'])) {
for ($i = 0; isset($action_info['#identifiers'][$i]); $i++) {
$matches = configuration_fetch($action_info['#identifiers'][$i], $action_context);
// TODO Should we set an error if count($matches) > 1 ?
if (!empty($matches)) {
$action_context->identifiers[$i] = $matches[0]->item;
// Make an id=>identifier map for easier access
if ($action_context->id) {
$identifiers[$action_context->id] =& $action_context->identifiers[$i];
}
}
}
}
}
// Cleanup items
unset($action_context->build_data, $action_context->form_state);
if ($action_info['#cleanup map']) {
configuration_apply_map($action_context, $action_info['#cleanup map']);
}
}