summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-03-29 17:00:13 (GMT)
committerwebchick2013-03-29 17:00:13 (GMT)
commita64d7b7db6ee304842d83ef0ffd643438d62f9da (patch)
treeafee171629d4de1e7d2e4dd3b2f0fa83b335a2bf
parentef63cffdf3dc2a873c0e1406f7b1a4a05e0c73aa (diff)
Issue #1939024 by Alan Evans, mtift, Crell: Convert action_admin_manage() to a new-style Controller.
-rw-r--r--core/modules/action/action.admin.inc126
-rw-r--r--core/modules/action/action.module12
-rw-r--r--core/modules/action/action.routing.yml20
-rw-r--r--core/modules/action/lib/Drupal/action/Controller/ActionController.php139
-rw-r--r--core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php68
5 files changed, 231 insertions, 134 deletions
diff --git a/core/modules/action/action.admin.inc b/core/modules/action/action.admin.inc
index c9db258..822284c 100644
--- a/core/modules/action/action.admin.inc
+++ b/core/modules/action/action.admin.inc
@@ -6,125 +6,6 @@
*/
/**
- * 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'),
- $instances_present ? t('Operations') : '',
- );
- $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();
- $row[] = $action->type;
- $row[] = check_plain($action->label);
- $links = array();
- if ($action->parameters) {
- $links['configure'] = array(
- 'title' => t('configure'),
- 'href' => "admin/config/system/actions/configure/$action->aid",
- );
- $links['delete'] = array(
- 'title' => t('delete'),
- 'href' => "admin/config/system/actions/delete/$action->aid",
- );
- }
- $row[] = array(
- 'data' => array(
- '#type' => 'operations',
- '#links' => $links,
- ),
- );
-
- $rows[] = $row;
- }
-
- if ($rows) {
- $pager = theme('pager');
- if (!empty($pager)) {
- $rows[] = 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' => $rows)));
- }
-
- 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' => 'details',
- '#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
@@ -287,10 +168,3 @@ function action_admin_delete_orphans_post($orphaned) {
}
}
-/**
- * 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');
-}
diff --git a/core/modules/action/action.module b/core/modules/action/action.module
index 6396caf..4d8fc04 100644
--- a/core/modules/action/action.module
+++ b/core/modules/action/action.module
@@ -60,16 +60,13 @@ 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',
+ 'route_name' => 'action_admin',
);
$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,
- 'file' => 'action.admin.inc',
+ 'route_name' => 'action_admin_manage',
);
$items['admin/config/system/actions/configure'] = array(
'title' => 'Configure an advanced action',
@@ -89,10 +86,9 @@ function action_menu() {
);
$items['admin/config/system/actions/orphan'] = array(
'title' => 'Remove orphans',
- 'page callback' => 'action_admin_remove_orphans',
- 'access arguments' => array('administer actions'),
+ 'description' => 'Remove actions that are in the database but not supported by any enabled module.',
+ 'route_name' => 'action_admin_orphans_remove',
'type' => MENU_CALLBACK,
- 'file' => 'action.admin.inc',
);
return $items;
}
diff --git a/core/modules/action/action.routing.yml b/core/modules/action/action.routing.yml
new file mode 100644
index 0000000..c4a2c0a
--- /dev/null
+++ b/core/modules/action/action.routing.yml
@@ -0,0 +1,20 @@
+action_admin:
+ pattern: '/admin/config/system/actions'
+ defaults:
+ _content: '\Drupal\action\Controller\ActionController::adminManage'
+ requirements:
+ _permission: 'administer actions'
+
+action_admin_manage:
+ pattern: '/admin/config/system/actions/manage'
+ defaults:
+ _content: '\Drupal\action\Controller\ActionController::adminManage'
+ requirements:
+ _permission: 'administer actions'
+
+action_admin_orphans_remove:
+ pattern: '/admin/config/system/actions/orphan'
+ defaults:
+ _content: '\Drupal\action\Controller\ActionController::adminRemoveOrphans'
+ requirements:
+ _permission: 'administer actions'
diff --git a/core/modules/action/lib/Drupal/action/Controller/ActionController.php b/core/modules/action/lib/Drupal/action/Controller/ActionController.php
new file mode 100644
index 0000000..09423fb
--- /dev/null
+++ b/core/modules/action/lib/Drupal/action/Controller/ActionController.php
@@ -0,0 +1,139 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\action\Controller\ActionController.
+ */
+
+namespace Drupal\action\Controller;
+
+use Drupal\action\Form\ActionAdminManageForm;
+use Drupal\Core\ControllerInterface;
+use Drupal\Core\Database\Connection;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpFoundation\RedirectResponse;
+
+/**
+ * Controller providing page callbacks for the action admin interface.
+ */
+class ActionController implements ControllerInterface {
+
+ /**
+ * The database connection object for this controller.
+ *
+ * @var \Drupal\Core\Database\Connection
+ */
+ protected $database;
+
+ /**
+ * Constructs a new ActionController.
+ *
+ * @param \Drupal\Core\Database\Connection $database
+ * The database connection object to be used by this controller.
+ */
+ public function __construct(Connection $database) {
+ $this->database = $database;
+ }
+
+ /**
+ * Implements \Drupal\Core\ControllerInterface::create().
+ */
+ public static function create(ContainerInterface $container) {
+ return new static($container->get('database'));
+ }
+
+ /**
+ * Displays an overview of available and configured actions.
+ *
+ * @return
+ * A render array containing a table of existing actions and the advanced
+ * action creation form.
+ */
+ public function adminManage() {
+ 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 = $this->database->query("SELECT aid FROM {actions} WHERE parameters <> ''")->fetchField();
+ $header = array(
+ array('data' => t('Action type'), 'field' => 'type'),
+ array('data' => t('Label'), 'field' => 'label'),
+ $instances_present ? t('Operations') : '',
+ );
+ $query = $this->database->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();
+ $row[] = $action->type;
+ $row[] = check_plain($action->label);
+ $links = array();
+ if ($action->parameters) {
+ $links['configure'] = array(
+ 'title' => t('configure'),
+ 'href' => "admin/config/system/actions/configure/$action->aid",
+ );
+ $links['delete'] = array(
+ 'title' => t('delete'),
+ 'href' => "admin/config/system/actions/delete/$action->aid",
+ );
+ }
+ $row[] = array(
+ 'data' => array(
+ '#type' => 'operations',
+ '#links' => $links,
+ ),
+ );
+
+ $rows[] = $row;
+ }
+
+ if ($rows) {
+ $pager = theme('pager');
+ if (!empty($pager)) {
+ $rows[] = array(array('data' => $pager, 'colspan' => '3'));
+ }
+ $build['action_header'] = array(
+ '#markup' => '<h3>' . t('Available actions:') . '</h3>'
+ );
+ $build['action_table'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ );
+ }
+
+ if ($actions_map) {
+ $build['action_admin_manage_form'] = drupal_get_form(new ActionAdminManageForm(), $options);
+ }
+
+ return $build;
+ }
+
+ /**
+ * Removes actions that are in the database but not supported by any enabled module.
+ */
+ public function adminRemoveOrphans() {
+ action_synchronize(TRUE);
+ return new RedirectResponse(url('admin/config/system/actions', array('absolute' => TRUE)));
+ }
+
+}
diff --git a/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php
new file mode 100644
index 0000000..269ce65
--- /dev/null
+++ b/core/modules/action/lib/Drupal/action/Form/ActionAdminManageForm.php
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\action\Form\ActionAdminManageForm.
+ */
+
+namespace Drupal\action\Form;
+
+use Drupal\Core\Form\FormInterface;
+
+/**
+ * Provides a configuration form for configurable actions.
+ */
+class ActionAdminManageForm implements FormInterface {
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::getFormID().
+ */
+ public function getFormID() {
+ return 'action_admin_manage';
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::buildForm().
+ *
+ * @param array $options
+ * An array of configurable actions.
+ */
+ public function buildForm(array $form, array &$form_state, array $options = array()) {
+ $form['parent'] = array(
+ '#type' => 'details',
+ '#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;
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::validateForm().
+ */
+ public function validateForm(array &$form, array &$form_state) {
+ }
+
+ /**
+ * Implements \Drupal\Core\Form\FormInterface::submitForm().
+ */
+ public function submitForm(array &$form, array &$form_state) {
+ if ($form_state['values']['action']) {
+ $form_state['redirect'] = 'admin/config/system/actions/configure/' . $form_state['values']['action'];
+ }
+ }
+
+}