Issue #1939024 by Alan Evans, mtift, Crell: Convert action_admin_manage() to a new-style Controller.
parent
ef63cffdf3
commit
a64d7b7db6
|
@ -5,125 +5,6 @@
|
||||||
* Admin page callbacks for the Action module.
|
* 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'),
|
|
||||||
$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.
|
* Form constructor for the configuration of a single action.
|
||||||
*
|
*
|
||||||
|
@ -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');
|
|
||||||
}
|
|
||||||
|
|
|
@ -60,16 +60,13 @@ function action_menu() {
|
||||||
$items['admin/config/system/actions'] = array(
|
$items['admin/config/system/actions'] = array(
|
||||||
'title' => 'Actions',
|
'title' => 'Actions',
|
||||||
'description' => 'Manage the actions defined for your site.',
|
'description' => 'Manage the actions defined for your site.',
|
||||||
'access arguments' => array('administer actions'),
|
'route_name' => 'action_admin',
|
||||||
'page callback' => 'action_admin_manage',
|
|
||||||
'file' => 'action.admin.inc',
|
|
||||||
);
|
);
|
||||||
$items['admin/config/system/actions/manage'] = array(
|
$items['admin/config/system/actions/manage'] = array(
|
||||||
'title' => 'Manage actions',
|
'title' => 'Manage actions',
|
||||||
'description' => 'Manage the actions defined for your site.',
|
'description' => 'Manage the actions defined for your site.',
|
||||||
'page callback' => 'action_admin_manage',
|
|
||||||
'type' => MENU_DEFAULT_LOCAL_TASK,
|
'type' => MENU_DEFAULT_LOCAL_TASK,
|
||||||
'file' => 'action.admin.inc',
|
'route_name' => 'action_admin_manage',
|
||||||
);
|
);
|
||||||
$items['admin/config/system/actions/configure'] = array(
|
$items['admin/config/system/actions/configure'] = array(
|
||||||
'title' => 'Configure an advanced action',
|
'title' => 'Configure an advanced action',
|
||||||
|
@ -89,10 +86,9 @@ function action_menu() {
|
||||||
);
|
);
|
||||||
$items['admin/config/system/actions/orphan'] = array(
|
$items['admin/config/system/actions/orphan'] = array(
|
||||||
'title' => 'Remove orphans',
|
'title' => 'Remove orphans',
|
||||||
'page callback' => 'action_admin_remove_orphans',
|
'description' => 'Remove actions that are in the database but not supported by any enabled module.',
|
||||||
'access arguments' => array('administer actions'),
|
'route_name' => 'action_admin_orphans_remove',
|
||||||
'type' => MENU_CALLBACK,
|
'type' => MENU_CALLBACK,
|
||||||
'file' => 'action.admin.inc',
|
|
||||||
);
|
);
|
||||||
return $items;
|
return $items;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
|
@ -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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue