Commit ef2e45b0 authored by webchick's avatar webchick
Browse files

Issue #2089635 by tim.plunkett, disasm, larowlan: Convert non-test non-form...

Issue #2089635 by tim.plunkett, disasm, larowlan: Convert non-test non-form page callbacks to routes and controllers.
parent 61fcb6fc
...@@ -410,6 +410,10 @@ services: ...@@ -410,6 +410,10 @@ services:
arguments: ['@entity.manager'] arguments: ['@entity.manager']
tags: tags:
- { name: access_check } - { name: access_check }
access_check.theme:
class: Drupal\Core\Theme\ThemeAccessCheck
tags:
- { name: access_check }
maintenance_mode_subscriber: maintenance_mode_subscriber:
class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber
tags: tags:
......
...@@ -475,6 +475,7 @@ function menu_get_item($path = NULL, $router_item = NULL) { ...@@ -475,6 +475,7 @@ function menu_get_item($path = NULL, $router_item = NULL) {
// occurs rarely, likely due to a race condition of multiple rebuilds. // occurs rarely, likely due to a race condition of multiple rebuilds.
if (\Drupal::state()->get('menu_rebuild_needed') || !\Drupal::state()->get('menu.masks')) { if (\Drupal::state()->get('menu_rebuild_needed') || !\Drupal::state()->get('menu.masks')) {
menu_router_rebuild(); menu_router_rebuild();
\Drupal::service('router.builder')->rebuild();
} }
$original_map = arg(NULL, $path); $original_map = arg(NULL, $path);
...@@ -1024,12 +1025,32 @@ function menu_item_route_access(Route $route, $href, &$map) { ...@@ -1024,12 +1025,32 @@ function menu_item_route_access(Route $route, $href, &$map) {
* it's 2. Defaults to 1. * it's 2. Defaults to 1.
* @param $path * @param $path
* See menu_get_item() for more on this. Defaults to the current path. * See menu_get_item() for more on this. Defaults to the current path.
*
* @todo Remove this function in https://drupal.org/node/2091399.
*/ */
function menu_get_object($type = 'node', $position = 1, $path = NULL) { function menu_get_object($type = 'node', $position = 1, $path = NULL) {
$router_item = menu_get_item($path); $router_item = menu_get_item($path);
if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') { if (empty($router_item['map'][$position])) {
return;
}
if (isset($router_item['load_functions'][$position]) && $router_item['load_functions'][$position] == $type . '_load') {
return $router_item['map'][$position]; return $router_item['map'][$position];
} }
// If the path is route-based, use the route path instead of the menu item.
// The most common use of this function is for the node page, which has a
// route path of '/node/{node}'. By splitting that path into parts, we check
// for the $type wrapped in curly braces at the correct $position, returning
// the value found there.
$request = \Drupal::request();
if ($request->attributes->has(RouteObjectInterface::ROUTE_OBJECT)) {
$path = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT)->getPath();
$parts = explode('/', ltrim($path, '/'));
if (isset($parts[$position]) && $parts[$position] == '{' . $type . '}') {
return $router_item['map'][$position];
}
}
} }
/** /**
......
...@@ -70,15 +70,14 @@ ...@@ -70,15 +70,14 @@
* @return * @return
* Boolean TRUE if the theme is enabled or is the site administration theme; * Boolean TRUE if the theme is enabled or is the site administration theme;
* FALSE otherwise. * FALSE otherwise.
*
* @deprecated Use \Drupal::service('access_check.theme')->checkAccess().
*/ */
function drupal_theme_access($theme) { function drupal_theme_access($theme) {
if (is_object($theme)) { if (is_object($theme)) {
return !empty($theme->status); $theme = $theme->name;
}
else {
$themes = list_themes();
return !empty($themes[$theme]->status);
} }
return Drupal::service('access_check.theme')->checkAccess($theme);
} }
/** /**
......
...@@ -57,6 +57,8 @@ public function getFormName() { ...@@ -57,6 +57,8 @@ public function getFormName() {
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation'; $form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription()); $form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1); $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
...@@ -68,15 +70,6 @@ public function buildForm(array $form, array &$form_state) { ...@@ -68,15 +70,6 @@ public function buildForm(array $form, array &$form_state) {
return $form; return $form;
} }
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -56,6 +56,8 @@ public function getFormName() { ...@@ -56,6 +56,8 @@ public function getFormName() {
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state); $form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation'; $form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription()); $form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1); $form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
...@@ -75,15 +77,6 @@ public function form(array $form, array &$form_state) { ...@@ -75,15 +77,6 @@ public function form(array $form, array &$form_state) {
return $form; return $form;
} }
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -44,7 +44,7 @@ public function getFormName() { ...@@ -44,7 +44,7 @@ public function getFormName() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildForm(array $form, array &$form_state) { public function buildForm(array $form, array &$form_state) {
drupal_set_title($this->getQuestion(), PASS_THROUGH); $form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation'; $form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription()); $form['description'] = array('#markup' => $this->getDescription());
......
<?php
/**
* @file
* Contains \Drupal\Core\Theme\ThemeAccessCheck.
*/
namespace Drupal\Core\Theme;
use Drupal\Core\Access\StaticAccessCheckInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
* Access check for a theme.
*/
class ThemeAccessCheck implements StaticAccessCheckInterface {
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_theme');
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
return $this->checkAccess($request->attributes->get('theme')) ? static::ALLOW : static::DENY;
}
/**
* Checks access to a theme.
*
* @param string $theme
* The name of a theme.
*
* @return bool
* TRUE if the theme is enabled, FALSE otherwise.
*/
public function checkAccess($theme) {
$themes = list_themes();
return !empty($themes[$theme]->status);
}
}
...@@ -142,13 +142,6 @@ function aggregator_menu() { ...@@ -142,13 +142,6 @@ function aggregator_menu() {
'title' => 'Categories', 'title' => 'Categories',
'route_name' => 'aggregator.categories', 'route_name' => 'aggregator.categories',
); );
$items['aggregator/opml'] = array(
'title' => 'OPML feed',
'page callback' => 'aggregator_page_opml',
'access arguments' => array('access news feeds'),
'type' => MENU_CALLBACK,
'file' => 'aggregator.pages.inc',
);
$items['aggregator/categories/%aggregator_category'] = array( $items['aggregator/categories/%aggregator_category'] = array(
'title callback' => '_aggregator_category_title', 'title callback' => '_aggregator_category_title',
'title arguments' => array(2), 'title arguments' => array(2),
......
...@@ -114,6 +114,8 @@ function template_preprocess_aggregator_item(&$variables) { ...@@ -114,6 +114,8 @@ function template_preprocess_aggregator_item(&$variables) {
* An OPML formatted string. * An OPML formatted string.
* *
* @see aggregator_menu() * @see aggregator_menu()
*
* @deprecated Use \Drupal\aggregator\Controller\AggregatorController::opmlPage()
*/ */
function aggregator_page_opml($cid = NULL) { function aggregator_page_opml($cid = NULL) {
if ($cid) { if ($cid) {
......
...@@ -137,3 +137,12 @@ aggregator.categorize_feed_form: ...@@ -137,3 +137,12 @@ aggregator.categorize_feed_form:
_form: '\Drupal\aggregator\Form\CategorizeFeedForm' _form: '\Drupal\aggregator\Form\CategorizeFeedForm'
requirements: requirements:
_permission: 'administer news feeds' _permission: 'administer news feeds'
aggregator.opml_page:
path: '/aggregator/opml/{cid}'
defaults:
_title: 'OPML feed'
_controller: '\Drupal\aggregator\Controller\AggregatorController::opmlPage'
cid: null
requirements:
_permission: 'access news feeds'
...@@ -346,4 +346,12 @@ public function sources() { ...@@ -346,4 +346,12 @@ public function sources() {
return $build; return $build;
} }
/**
* @todo Remove aggregator_opml().
*/
public function opmlPage($cid = NULL) {
module_load_include('pages.inc', 'aggregator');
return aggregator_page_opml($cid);
}
} }
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
* Page callback: Attaches CSS for the block region demo. * Page callback: Attaches CSS for the block region demo.
* *
* @see block_menu() * @see block_menu()
*
* @deprecated Use \Drupal\block\Controller\BlockController::demo()
*/ */
function block_admin_demo($theme = NULL) { function block_admin_demo($theme = NULL) {
return array( return array(
......
...@@ -136,14 +136,10 @@ function block_menu() { ...@@ -136,14 +136,10 @@ function block_menu() {
); );
$items["admin/structure/block/demo/$key"] = array( $items["admin/structure/block/demo/$key"] = array(
'title' => check_plain($theme->info['name']), 'title' => check_plain($theme->info['name']),
'page callback' => 'block_admin_demo', 'route_name' => 'block.admin_demo',
'page arguments' => array($key),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
'access callback' => '_block_themes_access',
'access arguments' => array($key),
'theme callback' => '_block_custom_theme', 'theme callback' => '_block_custom_theme',
'theme arguments' => array($key), 'theme arguments' => array($key),
'file' => 'block.admin.inc',
); );
} }
return $items; return $items;
......
block.admin_demo:
path: '/admin/structure/block/demo/{theme}'
defaults:
_content: '\Drupal\block\Controller\BlockController::demo'
options:
_access_mode: 'ALL'
requirements:
_access_theme: 'TRUE'
_permission: 'administer blocks'
block.admin_block_delete: block.admin_block_delete:
path: '/admin/structure/block/manage/{block}/delete' path: '/admin/structure/block/manage/{block}/delete'
defaults: defaults:
......
...@@ -13,7 +13,3 @@ services: ...@@ -13,7 +13,3 @@ services:
class: Drupal\block\Routing\RouteSubscriber class: Drupal\block\Routing\RouteSubscriber
tags: tags:
- { name: event_subscriber} - { name: event_subscriber}
block.theme_access_check:
class: Drupal\block\Access\BlockThemeAccessCheck
tags:
- { name: access_check}
<?php
/**
* @file
* Contains \Drupal\block\Controller\BlockController.
*/
namespace Drupal\block\Controller;
/**
* Controller routines for block routes.
*/
class BlockController {
/**
* @todo Remove block_admin_demo().
*/
public function demo($theme) {
module_load_include('admin.inc', 'block');
return block_admin_demo($theme);
}
}
...@@ -46,7 +46,11 @@ public function routes(RouteBuildEvent $event) { ...@@ -46,7 +46,11 @@ public function routes(RouteBuildEvent $event) {
'theme' => $key, 'theme' => $key,
), ),
array( array(
'_block_themes_access' => 'TRUE', '_access_theme' => 'TRUE',
'_permission' => 'administer blocks',
),
array(
'_access_mode' => 'ALL',
) )
); );
$collection->add("block.admin_display_$key", $route); $collection->add("block.admin_display_$key", $route);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
* *
* @see comment_menu() * @see comment_menu()
* @see comment_multiple_delete_confirm() * @see comment_multiple_delete_confirm()
*
* @deprecated Use \Drupal\comment\Controller\CommentController::adminPage()
*/ */
function comment_admin($type = 'new') { function comment_admin($type = 'new') {
$request = \Drupal::request(); $request = \Drupal::request();
......
...@@ -185,10 +185,8 @@ function comment_menu() { ...@@ -185,10 +185,8 @@ function comment_menu() {
$items['admin/content/comment'] = array( $items['admin/content/comment'] = array(
'title' => 'Comments', 'title' => 'Comments',
'description' => 'List and edit site comments and the comment approval queue.', 'description' => 'List and edit site comments and the comment approval queue.',
'page callback' => 'comment_admin', 'route_name' => 'comment.admin',
'access arguments' => array('administer comments'),
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM, 'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
'file' => 'comment.admin.inc',
); );
// Tabs begin here. // Tabs begin here.
$items['admin/content/comment/new'] = array( $items['admin/content/comment/new'] = array(
...@@ -198,8 +196,7 @@ function comment_menu() { ...@@ -198,8 +196,7 @@ function comment_menu() {
$items['admin/content/comment/approval'] = array( $items['admin/content/comment/approval'] = array(
'title' => 'Unapproved comments', 'title' => 'Unapproved comments',
'title callback' => 'comment_count_unpublished', 'title callback' => 'comment_count_unpublished',
'page arguments' => array('approval'), 'route_name' => 'comment.admin_approval',
'access arguments' => array('administer comments'),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
); );
$items['comment/%comment'] = array( $items['comment/%comment'] = array(
......
comment.admin:
path: '/admin/content/comment'
defaults:
_title: 'Comments'
_content: '\Drupal\comment\Controller\CommentController::adminPage'
type: 'new'
requirements:
_permission: 'administer comments'
comment.admin_approval:
path: '/admin/content/comment/approval'
defaults:
_title: 'Unapproved comments'
_content: '\Drupal\comment\Controller\CommentController::adminPage'
type: 'approval'
requirements:
_permission: 'administer comments'
comment.edit_page: comment.edit_page:
path: '/comment/{comment}/edit' path: '/comment/{comment}/edit'
defaults: defaults:
......
...@@ -271,4 +271,12 @@ public function renderNewCommentsNodeLinks(Request $request) { ...@@ -271,4 +271,12 @@ public function renderNewCommentsNodeLinks(Request $request) {
return new JsonResponse($links); return new JsonResponse($links);
} }
/**
* @todo Remove comment_admin().
*/
public function adminPage($type) {
module_load_include('admin.inc', 'comment');
return comment_admin($type);
}
} }
...@@ -53,7 +53,7 @@ function testCommentInterface() { ...@@ -53,7 +53,7 @@ function testCommentInterface() {
$this->assertTrue($this->commentExists($comment), 'Comment found.'); $this->assertTrue($this->commentExists($comment), 'Comment found.');
// Check comment display. // Check comment display.
$this->drupalGet('node/' . $this->node->id() . '/' . $comment->id()); $this->drupalGet('node/' . $this->node->id());
$this->assertText($subject_text, 'Individual comment subject found.'); $this->assertText($subject_text, 'Individual comment subject found.');
$this->assertText($comment_text, 'Individual comment body found.'); $this->assertText($comment_text, 'Individual comment body found.');
......
...@@ -68,7 +68,7 @@ function testThreadedCommentView() { ...@@ -68,7 +68,7 @@ function testThreadedCommentView() {
$this->assertTrue($this->commentExists($comment), 'Comment found.'); $this->assertTrue($this->commentExists($comment), 'Comment found.');
// Check comment display. // Check comment display.
$this->drupalGet('node/' . $this->node->id() . '/' . $comment->id()); $this->drupalGet('node/' . $this->node->id());
$this->assertText($comment_subject, 'Individual comment subject found.'); $this->assertText($comment_subject, 'Individual comment subject found.');
$this->assertText($comment_text, 'Individual comment body found.'); $this->assertText($comment_text, 'Individual comment body found.');
......
...@@ -80,31 +80,22 @@ function contact_menu() { ...@@ -80,31 +80,22 @@ function contact_menu() {
$items['contact'] = array( $items['contact'] = array(
'title' => 'Contact', 'title' => 'Contact',
'page callback' => 'contact_site_page', 'route_name' => 'contact.site_page',
'access arguments' => array('access site-wide contact form'),
'menu_name' => 'footer', 'menu_name' => 'footer',
'type' => MENU_SUGGESTED_ITEM, 'type' => MENU_SUGGESTED_ITEM,
'file' => 'contact.pages.inc',
); );
$items['contact/%contact_category'] = array( $items['contact/%contact_category'] = array(
'title' => 'Contact category form', 'title' => 'Contact category form',
'title callback' => 'entity_page_label', 'title callback' => 'entity_page_label',
'title arguments' => array(1), 'title arguments' => array(1),
'page callback' => 'contact_site_page', 'route_name' => 'contact.site_page_category',
'page arguments' => array(1),
'access arguments' => array('access site-wide contact form'),
'type' => MENU_VISIBLE_IN_BREADCRUMB, 'type' => MENU_VISIBLE_IN_BREADCRUMB,
'file' => 'contact.pages.inc',
); );
$items['user/%user/contact'] = array( $items['user/%user/contact'] = array(
'title' => 'Contact', 'title' => 'Contact',
'page callback' => 'contact_personal_page', 'route_name' => 'contact.personal_page',
'page arguments' => array(1),
'type' => MENU_LOCAL_TASK, 'type' => MENU_LOCAL_TASK,
'access callback' => '_contact_personal_tab_access',