Commit 523c8b6c authored by alexpott's avatar alexpott

Issue #2089671 by disasm, tim.plunkett: Convert non-test form callbacks to new form controller.

parent b13a82c2
......@@ -195,11 +195,7 @@ function book_menu() {
);
$items['node/%node/outline/remove'] = array(
'title' => 'Remove from outline',
'page callback' => 'drupal_get_form',
'page arguments' => array('book_remove_form', 1),
'access callback' => '_book_outline_remove_access',
'access arguments' => array(1),
'file' => 'book.pages.inc',
'route_name' => 'book.remove',
);
return $items;
......
......@@ -30,6 +30,8 @@ function book_remove_button_submit($form, &$form_state) {
* @see book_remove_form_submit()
* @see book_menu()
* @ingroup forms
*
* @deprecated Use \Drupal\book\Form\BookForm::remove()
*/
function book_remove_form($form, &$form_state, EntityInterface $node) {
$form['#node'] = $node;
......
......@@ -50,3 +50,15 @@ book.admin_edit:
_permission: 'administer book outlines'
_entity_access: 'node.view'
node: \d+
book.remove:
path: '/node/{node}/outline/remove'
defaults:
_content: '\Drupal\book\Form\BookForm::remove'
_title: 'Remove from outline'
options:
_access_mode: 'ALL'
requirements:
_permission: 'administer book outlines'
_entity_access: 'node.view'
_access_book_removable: 'TRUE'
......@@ -5,3 +5,9 @@ services:
book.export:
class: Drupal\book\BookExport
arguments: ['@entity.manager']
access_check.book.removable:
class: Drupal\book\Access\BookNodeIsRemovableAccessCheck
arguments: ['@book.manager']
tags:
- { name: access_check }
<?php
/**
* @file
* Contains Drupal\book\Access\BookNodeIsRemovableAccessCheck.
*/
namespace Drupal\book\Access;
use Drupal\book\BookManager;
use Drupal\Core\Access\StaticAccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Determines whether the requested node can be removed from its book.
*/
class BookNodeIsRemovableAccessCheck implements StaticAccessCheckInterface {
/**
* Book Manager Service.
*
* @var \Drupal\book\BookManager
*/
protected $bookManager;
/**
* Constructs a BookNodeIsRemovableAccessCheck object.
*
* @param \Drupal\book\BookManager $book_manager
* Book Manager Service.
*/
public function __construct(BookManager $book_manager) {
$this->bookManager = $book_manager;
}
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_book_removable');
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
$node = $request->attributes->get('node');
if (!empty($node)) {
return $this->bookManager->checkNodeIsRemovable($node) ? static::ALLOW : static::DENY;
}
return static::DENY;
}
}
<?php
/**
* @file
* Contains \Drupal\book\Form\BookForm.
*/
namespace Drupal\book\Form;
use Drupal\Core\Entity\EntityInterface;
/**
* Temporary form controller for book module.
*/
class BookForm {
/**
* Wraps book_remove_form().
*
* @todo Remove book_remove_form().
*/
public function remove(EntityInterface $node) {
module_load_include('pages.inc', 'book');
return drupal_get_form('book_remove_form', $node);
}
}
......@@ -183,10 +183,7 @@ function content_translation_menu() {
// Delete translation callback.
$items["$path/translations/delete/%language"] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('content_translation_delete_confirm', $entity_position, $language_position),
'access callback' => 'content_translation_delete_access',
'access arguments' => $args,
'route_name' => "content_translation.delete_$entity_type",
) + $item;
}
}
......
......@@ -248,6 +248,8 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua
/**
* Form constructor for the translation deletion confirmation.
*
* @deprecated Use \Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation()
*/
function content_translation_delete_confirm(array $form, array $form_state, EntityInterface $entity, Language $language) {
$langcode = $language->id;
......
......@@ -57,26 +57,28 @@ public function access(Route $route, Request $request) {
$translations = $entity->getTranslationLanguages();
$languages = language_list();
if ($operation == 'create') {
$source = language_load($request->attributes->get('source'));
$target = language_load($request->attributes->get('target'));
$source = !empty($source) ? $source : $entity->language();
$target = !empty($target) ? $target : language(Language::TYPE_CONTENT);
return ($source->id != $target->id
&& isset($languages[$source->id])
&& isset($languages[$target->id])
&& !isset($translations[$target->id])
&& $controller->getTranslationAccess($entity, $operation))
? static::ALLOW : static::DENY;
}
elseif ($operation == 'update') {
$language = language_load($request->attributes->get('language'));
$language = !empty($language) ? $language : language(Language::TYPE_CONTENT);
return isset($languages[$language->id])
&& $language->id != $entity->getUntranslated()->language()->id
&& isset($translations[$language->id])
&& $controller->getTranslationAccess($entity, $operation)
? static::ALLOW : static::DENY;
switch ($operation) {
case 'create':
$source = language_load($request->attributes->get('source'));
$target = language_load($request->attributes->get('target'));
$source = !empty($source) ? $source : $entity->language();
$target = !empty($target) ? $target : language(Language::TYPE_CONTENT);
return ($source->id != $target->id
&& isset($languages[$source->id])
&& isset($languages[$target->id])
&& !isset($translations[$target->id])
&& $controller->getTranslationAccess($entity, $operation))
? static::ALLOW : static::DENY;
case 'update':
case 'delete':
$language = language_load($request->attributes->get('language'));
$language = !empty($language) ? $language : language(Language::TYPE_CONTENT);
return isset($languages[$language->id])
&& $language->id != $entity->getUntranslated()->language()->id
&& isset($translations[$language->id])
&& $controller->getTranslationAccess($entity, $operation)
? static::ALLOW : static::DENY;
}
}
return static::DENY;
......
<?php
/**
* @file
* Contains \Drupal\content_translation\Form\ContentTranslationForm.
*/
namespace Drupal\content_translation\Form;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* Temporary form controller for content_translation module.
*/
class ContentTranslationForm {
/**
* Wraps content_translation_delete_confirm().
*
* @todo Remove content_translation_delete_confirm().
*/
public function deleteTranslation(EntityInterface $entity, $language) {
module_load_include('pages.inc', 'content_translation');
$language = language_load($language);
return drupal_get_form('content_translation_delete_confirm', $entity, $language);
}
}
......@@ -50,8 +50,9 @@ public function routes(RouteBuildEvent $event) {
$collection = $event->getRouteCollection();
foreach ($this->entityManager->getDefinitions() as $entity_type => $entity_info) {
if ($entity_info['translatable'] && isset($entity_info['translation'])) {
$path = '/' . str_replace($entity_info['menu_path_wildcard'], '{entity}', $entity_info['menu_base_path']) . '/translations';
$route = new Route(
'/' . str_replace($entity_info['menu_path_wildcard'], '{entity}', $entity_info['menu_base_path']) . "/translations",
$path,
array(
'_content' => '\Drupal\content_translation\Controller\ContentTranslationController::overview',
'_title' => 'Translate',
......@@ -72,7 +73,7 @@ public function routes(RouteBuildEvent $event) {
$collection->add("content_translation.translation_overview_$entity_type", $route);
$route = new Route(
'/' . str_replace($entity_info['menu_path_wildcard'], '{entity}', $entity_info['menu_base_path']) . "/translations/add/{source}/{target}",
$path . '/add/{source}/{target}',
array(
'_content' => '\Drupal\content_translation\Controller\ContentTranslationController::add',
'source' => NULL,
......@@ -95,7 +96,7 @@ public function routes(RouteBuildEvent $event) {
$collection->add("content_translation.translation_add_$entity_type", $route);
$route = new Route(
'/' . str_replace($entity_info['menu_path_wildcard'], '{entity}', $entity_info['menu_base_path']) . "/translations/edit/{language}",
$path . '/edit/{language}',
array(
'_content' => '\Drupal\content_translation\Controller\ContentTranslationController::edit',
'language' => NULL,
......@@ -114,6 +115,27 @@ public function routes(RouteBuildEvent $event) {
)
);
$collection->add("content_translation.translation_edit_$entity_type", $route);
$route = new Route(
$path . '/delete/{language}',
array(
'_content' => '\Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation',
'language' => NULL,
'_title' => 'Delete',
),
array(
'_permission' => 'translate any entity',
'_access_content_translation_manage' => 'delete',
),
array(
'parameters' => array(
'entity' => array(
'type' => 'entity:' . $entity_type,
),
),
)
);
$collection->add("content_translation.delete_$entity_type", $route);
}
}
}
......
......@@ -26,6 +26,8 @@ function language_admin_predefined_list() {
/**
* Builds the configuration form for language negotiation.
*
* @deprecated Use \Drupal\language\Form\LanguageForm::negotiation()
*/
function language_negotiation_configure_form() {
language_negotiation_include();
......
......@@ -94,11 +94,8 @@ function language_menu() {
// Language negotiation.
$items['admin/config/regional/language/detection'] = array(
'title' => 'Detection and selection',
'page callback' => 'drupal_get_form',
'page arguments' => array('language_negotiation_configure_form'),
'access arguments' => array('administer languages'),
'route_name' => 'language.negotiation',
'weight' => 10,
'file' => 'language.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/config/regional/language/detection/url'] = array(
......
......@@ -47,6 +47,14 @@ language.delete:
requirements:
_entity_access: 'language_entity.delete'
language.negotiation:
path: '/admin/config/regional/language/detection'
defaults:
_content: '\Drupal\language\Form\LanguageForm::negotiation'
_title: 'Detection and selection'
requirements:
_permission: 'administer languages'
language.negotiation_browser:
path: '/admin/config/regional/language/detection/browser'
defaults:
......
<?php
/**
* @file
* Contains \Drupal\language\Form\LanguageForm.
*/
namespace Drupal\language\Form;
/**
* Temporary form controller for language module.
*/
class LanguageForm {
/**
* Wraps language_negotiation_configure_form().
*
* @todo Remove language_negotiation_configure_form().
*/
public function negotiation() {
module_load_include('admin.inc', 'language');
return drupal_get_form('language_negotiation_configure_form');
}
}
<?php
/**
* @file
* Contains \Drupal\locale\Form\LocaleForm.
*/
namespace Drupal\locale\Form;
/**
* Temporary form controller for locale module.
*/
class LocaleForm {
/**
* Wraps locale_translate_import_form().
*
* @todo Remove locale_translate_import_form().
*/
public function import() {
module_load_include('bulk.inc', 'locale');
return drupal_get_form('locale_translate_import_form');
}
/**
* Wraps locale_translate_export_form().
*
* @todo Remove locale_translate_export_form().
*/
public function export() {
module_load_include('bulk.inc', 'locale');
return drupal_get_form('locale_translate_export_form');
}
/**
* Wraps locale_translation_status_form().
*
* @todo Remove locale_translation_status_form().
*/
public function status() {
module_load_include('pages.inc', 'locale');
return drupal_get_form('locale_translation_status_form');
}
}
......@@ -17,6 +17,8 @@
*
* @see locale_translate_import_form_submit()
* @ingroup forms
*
* @deprecated Use \Drupal\locale\Form\LocaleForm::import()
*/
function locale_translate_import_form($form, &$form_state) {
drupal_static_reset('language_list');
......@@ -144,6 +146,8 @@ function locale_translate_import_form_submit($form, &$form_state) {
*
* @see locale_translate_export_form_submit()
* @ingroup forms
*
* @deprecated Use \Drupal\locale\Form\LocaleForm::export()
*/
function locale_translate_export_form($form, &$form_state) {
$languages = language_list();
......
......@@ -182,21 +182,15 @@ function locale_menu() {
);
$items['admin/config/regional/translate/import'] = array(
'title' => 'Import',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_translate_import_form'),
'access arguments' => array('translate interface'),
'route_name' => 'locale.translate_import',
'weight' => 20,
'type' => MENU_LOCAL_TASK,
'file' => 'locale.bulk.inc',
);
$items['admin/config/regional/translate/export'] = array(
'title' => 'Export',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_translate_export_form'),
'access arguments' => array('translate interface'),
'route_name' => 'locale.translate_export',
'weight' => 30,
'type' => MENU_LOCAL_TASK,
'file' => 'locale.bulk.inc',
);
$items['admin/config/regional/translate/settings'] = array(
'title' => 'Settings',
......@@ -206,11 +200,8 @@ function locale_menu() {
);
$items['admin/reports/translations'] = array(
'title' => 'Available translation updates',
'route_name' => 'locale.translate_status',
'description' => 'Get a status report about available interface translations for your installed modules and themes.',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_translation_status_form'),
'access arguments' => array('translate interface'),
'file' => 'locale.pages.inc',
);
return $items;
......
......@@ -40,6 +40,8 @@ function locale_translation_manual_status() {
* Page callback: Display the current translation status.
*
* @see locale_menu()
*
* @deprecated Use \Drupal\locale\Form\LocaleForm::status()
*/
function locale_translation_status_form($form, &$form_state) {
module_load_include('translation.inc', 'locale');
......
......@@ -18,3 +18,27 @@ locale.translate_page:
_content: 'Drupal\locale\Controller\LocaleController::translatePage'
requirements:
_permission: 'translate interface'
locale.translate_import:
path: '/admin/config/regional/translate/import'
defaults:
_content: '\Drupal\locale\Form\LocaleForm::import'
_title: 'Import'
requirements:
_permission: 'translate interface'
locale.translate_export:
path: '/admin/config/regional/translate/export'
defaults:
_content: '\Drupal\locale\Form\LocaleForm::export'
_title: 'Export'
requirements:
_permission: 'translate interface'
locale.translate_status:
path: '/admin/reports/translations'
defaults:
_content: '\Drupal\locale\Form\LocaleForm::status'
_title: 'Available translation updates'
requirements:
_permission: 'translate interface'
......@@ -2,7 +2,7 @@
/**
* @file
* Contains Drupal\shortcut\Access\LinkDeleteAccessCheck.
* Contains Drupal\shortcut\Access\LinkAccessCheck.
*/
namespace Drupal\shortcut\Access;
......@@ -14,13 +14,13 @@
/**
* Provides an access check for shortcut link delete routes.
*/
class LinkDeleteAccessCheck implements StaticAccessCheckInterface {
class LinkAccessCheck implements StaticAccessCheckInterface {
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_shortcut_link_delete');
return array('_access_shortcut_link');
}
/**
......@@ -32,6 +32,7 @@ public function access(Route $route, Request $request) {
if ($shortcut_set = shortcut_set_load($set_name)) {
return shortcut_set_edit_access($shortcut_set) ? static::ALLOW : static::DENY;
}
return static::DENY;
}
}
<?php
/**
* @file
* Contains Drupal\shortcut\Access\ShortcutSetEditAccessCheck.
*/
namespace Drupal\shortcut\Access;
use Drupal\Core\Access\StaticAccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides an access check for shortcut link delete routes.
*/
class ShortcutSetEditAccessCheck implements StaticAccessCheckInterface {
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_shortcut_set_edit');
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
$account = \Drupal::currentUser();
$shortcut_set = $request->attributes->get('shortcut_set');
// Sufficiently-privileged users can edit their currently displayed shortcut
// set, but not other sets. Shortcut administrators can edit any set.
if ($account->hasPermission('administer shortcuts')) {
return static::ALLOW;
}
if ($account->hasPermission('customize shortcut links')) {
return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set() ? static::ALLOW : static::DENY;
}
return static::DENY;
}
}
<?php
/**
* @file
* Contains Drupal\shortcut\Access\ShortcutSetSwitchAccessCheck.
*/
namespace Drupal\shortcut\Access;
use Drupal\Core\Access\StaticAccessCheckInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides an access check for shortcut link delete routes.
*/
class ShortcutSetSwitchAccessCheck implements StaticAccessCheckInterface {
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_shortcut_set_switch');
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
$user = \Drupal::currentUser();
$account = $request->attributes->get('account');
if ($user->hasPermission('administer shortcuts')) {
// Administrators can switch anyone's shortcut set.
return static::ALLOW;
}
if (!$user->hasPermission('switch shortcut sets')) {
// The user has no permission to switch anyone's shortcut set.
return static::DENY;
}
if (!isset($account) || $user->id() == $account->id()) {
// Users with the 'switch shortcut sets' permission can switch their own
// shortcuts sets.
return static::ALLOW;
}
return static::DENY;
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Form\ShortcutForm.
*/
namespace Drupal\shortcut\Form;
use Drupal\menu_link\MenuLinkInterface;
use Drupal\shortcut\ShortcutSetInterface;
use Drupal\user\UserInterface;
/**
* Temporary form controller for shortcut module.
*/
class ShortcutForm {
/**
* Wraps shortcut_link_edit().
*
* @todo Remove shortcut_link_edit().
*/
public function edit(MenuLinkInterface $menu_link) {
module_load_include('admin.inc', 'shortcut');
return drupal_get_form('shortcut_link_edit', $menu_link);
}
/**
* Wraps shortcut_link_add().
*
* @todo Remove shortcut_link_add().
*/
public function add(ShortcutSetInterface $shortcut_set) {
module_load_include('admin.inc', 'shortcut');
return drupal_get_form('shortcut_link_add', $shortcut_set);
}
/**
* Wraps shortcut_set_switch().
*
* @todo Remove shortcut_set_switch().
*/
public function overview(UserInterface $user) {
module_load_include('admin.inc', 'shortcut');
return drupal_get_form('shortcut_set_switch', $user);
}
}