Commit 6e5ea17d authored by webchick's avatar webchick

Issue #1944756 by kim.pepper: Convert action_admin_configure() to a new-style Controller.

parent c454976b
......@@ -5,125 +5,6 @@
* Admin page callbacks for the Action module.
*/
/**
* 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';
}
/**
* Creates the form for confirmation of deleting an action.
*
......
......@@ -69,11 +69,8 @@ function action_menu() {
);
$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',
'route_name' => 'action_admin_configure',
);
$items['admin/config/system/actions/delete/%action'] = array(
'title' => 'Delete action',
......
......@@ -11,3 +11,10 @@ action_admin_orphans_remove:
_content: '\Drupal\action\Controller\ActionController::adminRemoveOrphans'
requirements:
_permission: 'administer actions'
action_admin_configure:
pattern: '/admin/config/system/actions/configure/{action}'
defaults:
_form: '\Drupal\action\Form\ActionAdminConfigureForm'
requirements:
_permission: 'administer actions'
<?php
/**
* @file
* Contains \Drupal\action\Form\ActionAdminConfigureForm.
*/
namespace Drupal\action\Form;
use Drupal\Core\Form\FormInterface;
/**
* Provides a form for configuring an action.
*/
class ActionAdminConfigureForm implements FormInterface {
/**
* Implements \Drupal\Core\Form\FormInterface::getFormID().
*/
public function getFormID() {
return 'action_admin_configure';
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, array &$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;
}
/**
* Implements \Drupal\Core\Form\FormInterface::validateForm().
*/
public function validateForm(array &$form, array &$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);
}
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, array &$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';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment