Commit ef2e45b0 authored by webchick's avatar webchick

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:
arguments: ['@entity.manager']
tags:
- { name: access_check }
access_check.theme:
class: Drupal\Core\Theme\ThemeAccessCheck
tags:
- { name: access_check }
maintenance_mode_subscriber:
class: Drupal\Core\EventSubscriber\MaintenanceModeSubscriber
tags:
......
......@@ -475,6 +475,7 @@ function menu_get_item($path = NULL, $router_item = NULL) {
// occurs rarely, likely due to a race condition of multiple rebuilds.
if (\Drupal::state()->get('menu_rebuild_needed') || !\Drupal::state()->get('menu.masks')) {
menu_router_rebuild();
\Drupal::service('router.builder')->rebuild();
}
$original_map = arg(NULL, $path);
......@@ -1024,12 +1025,32 @@ function menu_item_route_access(Route $route, $href, &$map) {
* it's 2. Defaults to 1.
* @param $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) {
$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];
}
// 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 @@
* @return
* Boolean TRUE if the theme is enabled or is the site administration theme;
* FALSE otherwise.
*
* @deprecated Use \Drupal::service('access_check.theme')->checkAccess().
*/
function drupal_theme_access($theme) {
if (is_object($theme)) {
return !empty($theme->status);
}
else {
$themes = list_themes();
return !empty($themes[$theme]->status);
$theme = $theme->name;
}
return Drupal::service('access_check.theme')->checkAccess($theme);
}
/**
......
......@@ -57,6 +57,8 @@ public function getFormName() {
public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
......@@ -68,15 +70,6 @@ public function buildForm(array $form, array &$form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/**
* {@inheritdoc}
*/
......
......@@ -56,6 +56,8 @@ public function getFormName() {
public function buildForm(array $form, array &$form_state) {
$form = parent::buildForm($form, $form_state);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$form['description'] = array('#markup' => $this->getDescription());
$form[$this->getFormName()] = array('#type' => 'hidden', '#value' => 1);
......@@ -75,15 +77,6 @@ public function form(array $form, array &$form_state) {
return $form;
}
/**
* {@inheritdoc}
*/
protected function init(array &$form_state) {
parent::init($form_state);
drupal_set_title($this->getQuestion(), PASS_THROUGH);
}
/**
* {@inheritdoc}
*/
......
......@@ -44,7 +44,7 @@ public function getFormName() {
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
drupal_set_title($this->getQuestion(), PASS_THROUGH);
$form['#title'] = $this->getQuestion();
$form['#attributes']['class'][] = 'confirmation';
$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() {
'title' => '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(
'title callback' => '_aggregator_category_title',
'title arguments' => array(2),
......
......@@ -114,6 +114,8 @@ function template_preprocess_aggregator_item(&$variables) {
* An OPML formatted string.
*
* @see aggregator_menu()
*
* @deprecated Use \Drupal\aggregator\Controller\AggregatorController::opmlPage()
*/
function aggregator_page_opml($cid = NULL) {
if ($cid) {
......
......@@ -137,3 +137,12 @@ aggregator.categorize_feed_form:
_form: '\Drupal\aggregator\Form\CategorizeFeedForm'
requirements:
_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() {
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 @@
* Page callback: Attaches CSS for the block region demo.
*
* @see block_menu()
*
* @deprecated Use \Drupal\block\Controller\BlockController::demo()
*/
function block_admin_demo($theme = NULL) {
return array(
......
......@@ -136,14 +136,10 @@ function block_menu() {
);
$items["admin/structure/block/demo/$key"] = array(
'title' => check_plain($theme->info['name']),
'page callback' => 'block_admin_demo',
'page arguments' => array($key),
'route_name' => 'block.admin_demo',
'type' => MENU_CALLBACK,
'access callback' => '_block_themes_access',
'access arguments' => array($key),
'theme callback' => '_block_custom_theme',
'theme arguments' => array($key),
'file' => 'block.admin.inc',
);
}
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:
path: '/admin/structure/block/manage/{block}/delete'
defaults:
......
......@@ -13,7 +13,3 @@ services:
class: Drupal\block\Routing\RouteSubscriber
tags:
- { 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) {
'theme' => $key,
),
array(
'_block_themes_access' => 'TRUE',
'_access_theme' => 'TRUE',
'_permission' => 'administer blocks',
),
array(
'_access_mode' => 'ALL',
)
);
$collection->add("block.admin_display_$key", $route);
......
......@@ -16,6 +16,8 @@
*
* @see comment_menu()
* @see comment_multiple_delete_confirm()
*
* @deprecated Use \Drupal\comment\Controller\CommentController::adminPage()
*/
function comment_admin($type = 'new') {
$request = \Drupal::request();
......
......@@ -185,10 +185,8 @@ function comment_menu() {
$items['admin/content/comment'] = array(
'title' => 'Comments',
'description' => 'List and edit site comments and the comment approval queue.',
'page callback' => 'comment_admin',
'access arguments' => array('administer comments'),
'route_name' => 'comment.admin',
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM,
'file' => 'comment.admin.inc',
);
// Tabs begin here.
$items['admin/content/comment/new'] = array(
......@@ -198,8 +196,7 @@ function comment_menu() {
$items['admin/content/comment/approval'] = array(
'title' => 'Unapproved comments',
'title callback' => 'comment_count_unpublished',
'page arguments' => array('approval'),
'access arguments' => array('administer comments'),
'route_name' => 'comment.admin_approval',
'type' => MENU_LOCAL_TASK,
);
$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:
path: '/comment/{comment}/edit'
defaults:
......
......@@ -271,4 +271,12 @@ public function renderNewCommentsNodeLinks(Request $request) {
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() {
$this->assertTrue($this->commentExists($comment), 'Comment found.');
// 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($comment_text, 'Individual comment body found.');
......
......@@ -68,7 +68,7 @@ function testThreadedCommentView() {
$this->assertTrue($this->commentExists($comment), 'Comment found.');
// 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_text, 'Individual comment body found.');
......
......@@ -80,31 +80,22 @@ function contact_menu() {
$items['contact'] = array(
'title' => 'Contact',
'page callback' => 'contact_site_page',
'access arguments' => array('access site-wide contact form'),
'route_name' => 'contact.site_page',
'menu_name' => 'footer',
'type' => MENU_SUGGESTED_ITEM,
'file' => 'contact.pages.inc',
);
$items['contact/%contact_category'] = array(
'title' => 'Contact category form',
'title callback' => 'entity_page_label',
'title arguments' => array(1),
'page callback' => 'contact_site_page',
'page arguments' => array(1),
'access arguments' => array('access site-wide contact form'),
'route_name' => 'contact.site_page_category',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
'file' => 'contact.pages.inc',
);
$items['user/%user/contact'] = array(
'title' => 'Contact',
'page callback' => 'contact_personal_page',
'page arguments' => array(1),
'route_name' => 'contact.personal_page',
'type' => MENU_LOCAL_TASK,
'access callback' => '_contact_personal_tab_access',
'access arguments' => array(1),
'weight' => 2,
'file' => 'contact.pages.inc',
);
return $items;
}
......@@ -118,41 +109,7 @@ function contact_menu() {
* @see contact_menu()
*/
function _contact_personal_tab_access(UserInterface $account) {
global $user;
// Anonymous users cannot have contact forms.
if ($account->isAnonymous()) {
return FALSE;
}
// Users may not contact themselves.
if ($user->id() == $account->id()) {
return FALSE;
}
// User administrators should always have access to personal contact forms.
if (user_access('administer users')) {
return TRUE;
}
// If requested user has been blocked, do not allow users to contact them.
if ($account->isBlocked()) {
return FALSE;
}
// If the requested user has disabled their contact form, do not allow users
// to contact them.
$account_data = \Drupal::service('user.data')->get('contact', $account->id(), 'enabled');
if (isset($account_data) && empty($account_data)) {
return FALSE;
}
// If the requested user did not save a preference yet, deny access if the
// configured default is disabled.
elseif (!\Drupal::config('contact.settings')->get('user_default_enabled')) {
return FALSE;
}
return user_access('access user contact forms');
return \Drupal::service('access_manager')->checkNamedRoute('contact.personal_page', array('user' => $account->id()));
}
/**
......
......@@ -21,6 +21,8 @@
* @see contact_menu()
* @see contact_site_form_submit()
* @ingroup forms
*
* @deprecated Use \Drupal\contact\Controller\ContactController::contactSitePage()
*/
function contact_site_page(Category $category = NULL) {
// Check if flood control has been activated for sending e-mails.
......@@ -66,6 +68,8 @@ function contact_site_page(Category $category = NULL) {
* @see contact_personal_form_submit()
*
* @ingroup forms
*
* @deprecated Use \Drupal\contact\Controller\ContactController::contactPersonalPage()
*/
function contact_personal_page($recipient) {
global $user;
......
......@@ -26,3 +26,28 @@ contact.category_edit:
_entity_form: contact_category.edit
requirements:
_entity_access: contact_category.update
contact.site_page:
path: '/contact'
defaults:
_title: 'Contact'
_content: '\Drupal\contact\Controller\ContactController::contactSitePage'
contact_category: NULL
requirements:
_permission: 'access site-wide contact form'
contact.site_page_category:
path: '/contact/{contact_category}'
defaults:
_title: 'Contact category form'
_content: '\Drupal\contact\Controller\ContactController::contactSitePage'
requirements:
_permission: 'access site-wide contact form'
contact.personal_page:
path: '/user/{user}/contact'
defaults:
_title: 'Contact'
_content: '\Drupal\contact\Controller\ContactController::contactPersonalPage'
requirements:
_access_contact_personal_tab: 'TRUE'
services:
access_check.contact_personal:
class: Drupal\contact\Access\ContactPageAccess
tags:
- { name: access_check }
arguments: ['@config.factory', '@user.data']
<?php
/**
* @file
* Contains \Drupal\contact\Access\ContactPageAccess.
*/
namespace Drupal\contact\Access;
use Drupal\Core\Access\StaticAccessCheckInterface;
use Drupal\Core\Config\ConfigFactory;
use Drupal\user\UserDataInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Access check for contact_personal_page route.
*/
class ContactPageAccess implements StaticAccessCheckInterface {
/**
* The contact settings config object.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The user data service.
*
* @var \Drupal\user\UserDataInterface;
*/
protected $userData;
/**
* Constructs a ContactPageAccess instance.
*
* @param \Drupal\Core\Config\ConfigFactory $config_factory
* The config factory.
* @param \Drupal\user\UserDataInterface $user_data
* The user data service.
*/
public function __construct(ConfigFactory $config_factory, UserDataInterface $user_data) {
$this->configFactory = $config_factory;
$this->userData = $user_data;
}
/**
* {@inheritdoc}
*/
public function appliesTo() {
return array('_access_contact_personal_tab');
}
/**
* {@inheritdoc}
*/
public function access(Route $route, Request $request) {
$contact_account = $request->attributes->get('user');
// @todo revisit after https://drupal.org/node/2048223
$user = \Drupal::currentUser();
// Anonymous users cannot have contact forms.
if ($contact_account->isAnonymous()) {
return static::DENY;
}
// Users may not contact themselves.
if ($user->id() == $contact_account->id()) {
return static::DENY;
}
// User administrators should always have access to personal contact forms.
if ($user->hasPermission('administer users')) {
return static::ALLOW;
}
// If requested user has been blocked, do not allow users to contact them.
if ($contact_account->isBlocked()) {
return static::DENY;
}
// If the requested user has disabled their contact form, do not allow users
// to contact them.
$account_data = $this->userData->get('contact', $contact_account->id(), 'enabled');
if (isset($account_data) && empty($account_data)) {
return static::DENY;
}
// If the requested user did not save a preference yet, deny access if the
// configured default is disabled.
else if (!$this->configFactory->get('contact.settings')->get('user_default_enabled')) {
return static::DENY;
}
return $user->hasPermission('access user contact forms') ? static::ALLOW : static::DENY;
}
}
<?php
/**
* @file
* Contains \Drupal\contact\Controller\ContactController.
*/
namespace Drupal\contact\Controller;
use Drupal\contact\CategoryInterface;
use Drupal\user\UserInterface;
/**
* Controller routines for contact routes.
*/
class ContactController {
/**
* @todo Remove contact_site_page().
*/
public function contactSitePage(CategoryInterface $contact_category = NULL) {
module_load_include('pages.inc', 'contact');
return contact_site_page($contact_category);
}
/**
* @todo Remove contact_personal_page().
*/