Commit 0d31d44d authored by webchick's avatar webchick

Issue #2052389 by pwolanin: Fixed All elements added to the Request attributes...

Issue #2052389 by pwolanin: Fixed All elements added to the Request attributes should have a _ prepended unless they come from the path.
parent 391755e4
......@@ -3169,7 +3169,7 @@ function drupal_page_set_cache(Response $response, Request $request) {
$cache = (object) array(
'cid' => $base_root . $request->getRequestUri(),
'data' => array(
'path' => $request->attributes->get('system_path'),
'path' => $request->attributes->get('_system_path'),
'body' => $response->getContent(),
'title' => drupal_get_title(),
'headers' => array(),
......
......@@ -1344,7 +1344,7 @@ function drupal_redirect_form($form_state) {
}
}
}
$url = url(Drupal::request()->attributes->get('system_path'), array(
$url = url(Drupal::request()->attributes->get('_system_path'), array(
'query' => Drupal::request()->query->all(),
'absolute' => TRUE,
));
......
......@@ -966,7 +966,7 @@ function _menu_link_translate(&$item, $translate = FALSE) {
*/
function menu_item_route_access(Route $route, $href, &$map) {
$request = Request::create('/' . $href);
$request->attributes->set('system_path', $href);
$request->attributes->set('_system_path', $href);
// Attempt to match this path to provide a fully built request to the
// access checker.
try {
......@@ -2629,7 +2629,7 @@ function menu_get_active_breadcrumb() {
// Don't show a link to the current page in the breadcrumb trail.
$end = end($active_trail);
if (Drupal::request()->attributes->get('system_path') == $end['href']) {
if (Drupal::request()->attributes->get('_system_path') == $end['href']) {
array_pop($active_trail);
}
......
......@@ -83,7 +83,7 @@ function current_path() {
// fallback code below, once the path alias logic has been figured out in
// http://drupal.org/node/1269742.
if (drupal_container()->isScopeActive('request')) {
$path = drupal_container()->get('request')->attributes->get('system_path');
$path = drupal_container()->get('request')->attributes->get('_system_path');
if ($path !== NULL) {
return $path;
}
......
......@@ -182,7 +182,7 @@ public function handleException(GetResponseForExceptionEvent $event) {
// instead. Assume those were authenticated by cookie, because the legacy
// router didn't support anything else.
// @todo Remove this check once the old router is fully removed.
if ($request->attributes->has('drupal_menu_item')) {
if ($request->attributes->has('_drupal_menu_item')) {
$active_providers = array('cookie');
}
else {
......
......@@ -41,7 +41,7 @@ public function content(Request $request, $_content) {
// We need to clean up the derived information and such so that the
// subrequest can be processed properly without leaking data through.
$attributes->remove('system_path');
$attributes->remove('_system_path');
$attributes->remove('_content');
$attributes->remove('_legacy');
......
......@@ -53,7 +53,7 @@ protected function forward(Request $request) {
$attributes = clone $request->attributes;
// We need to clean up the derived information and such so that the
// subrequest can be processed properly without leaking data through.
$attributes->remove('system_path');
$attributes->remove('_system_path');
$attributes->set('dialog', TRUE);
// Remove the accept header so the subrequest does not end up back in this
......
......@@ -81,7 +81,7 @@ public function on405Html(FlattenException $exception, Request $request) {
* The request object that triggered this exception.
*/
public function on403Html(FlattenException $exception, Request $request) {
$system_path = $request->attributes->get('system_path');
$system_path = $request->attributes->get('_system_path');
watchdog('access denied', $system_path, NULL, WATCHDOG_WARNING);
$path = $this->container->get('path.alias_manager')->getSystemPath(config('system.site')->get('page.403'));
......@@ -136,7 +136,7 @@ public function on403Html(FlattenException $exception, Request $request) {
* The request object that triggered this exception.
*/
public function on404Html(FlattenException $exception, Request $request) {
watchdog('page not found', check_plain($request->attributes->get('system_path')), NULL, WATCHDOG_WARNING);
watchdog('page not found', check_plain($request->attributes->get('_system_path')), NULL, WATCHDOG_WARNING);
// Check for and return a fast 404 page if configured.
$config = config('system.performance');
......@@ -151,7 +151,7 @@ public function on404Html(FlattenException $exception, Request $request) {
}
}
$system_path = $request->attributes->get('system_path');
$system_path = $request->attributes->get('_system_path');
// Keep old path for reference, and to allow forms to redirect to it.
if (!isset($_GET['destination'])) {
......
......@@ -55,7 +55,7 @@ public function content(Request $request, $_content) {
// We need to clean off the derived information and such so that the
// subrequest can be processed properly without leaking data through.
$attributes->remove('system_path');
$attributes->remove('_system_path');
$attributes->remove('_content');
$response = $this->httpKernel->forward($controller, $attributes->all(), $request->query->all());
......
......@@ -32,7 +32,7 @@ public function onKernelRequestAccessCheck(GetResponseEvent $event) {
$request_attributes = $event->getRequest()->attributes;
$router_item = $request_attributes->get('drupal_menu_item');
$router_item = $request_attributes->get('_drupal_menu_item');
// For legacy routes we do not allow any user not authenticated by cookie
// provider.
......
......@@ -37,7 +37,7 @@ class LegacyControllerSubscriber implements EventSubscriberInterface {
*/
public function onKernelControllerLegacy(FilterControllerEvent $event) {
$request = $event->getRequest();
$router_item = $request->attributes->get('drupal_menu_item');
$router_item = $request->attributes->get('_drupal_menu_item');
$controller = $event->getController();
// This BC logic applies only to functions. Otherwise, skip it.
......
......@@ -15,11 +15,11 @@
abstract class PathListenerBase {
public function extractPath(Request $request) {
$path = $request->attributes->get('system_path');
$path = $request->attributes->get('_system_path');
return isset($path) ? $path : trim($request->getPathInfo(), '/');
}
public function setPath(Request $request, $path) {
$request->attributes->set('system_path', $path);
$request->attributes->set('_system_path', $path);
}
}
......@@ -50,7 +50,7 @@ public function onKernelRequestConvertPath(GetResponseEvent $event) {
$request = $event->getRequest();
$path = trim($request->getPathInfo(), '/');
$path = $this->pathProcessor->processInbound($path, $request);
$request->attributes->set('system_path', $path);
$request->attributes->set('_system_path', $path);
// Also set an attribute that indicates whether we are using clean URLs.
$clean_urls = TRUE;
$base_url = $request->getBaseUrl();
......
......@@ -100,10 +100,10 @@ public function getRequest() {
* @api
*/
public function matchRequest(Request $request) {
if ($router_item = $this->matchDrupalItem($request->attributes->get('system_path'))) {
if ($router_item = $this->matchDrupalItem($request->attributes->get('_system_path'))) {
$ret = $this->convertDrupalItem($router_item);
// Stash the router item in the attributes while we're transitioning.
$ret['drupal_menu_item'] = $router_item;
$ret['_drupal_menu_item'] = $router_item;
// Most legacy controllers (aka page callbacks) are in a separate file,
// so we have to include that.
......
......@@ -80,15 +80,15 @@ public function __construct(Connection $connection, $table = 'router') {
*/
public function getRouteCollectionForRequest(Request $request) {
// The 'system_path' has language prefix stripped and path alias resolved,
// The '_system_path' has language prefix stripped and path alias resolved,
// whereas getPathInfo() returns the requested path. In Drupal, the request
// always contains a system_path attribute, but this component may get
// adopted by non-Drupal projects. Some unit tests also skip initializing
// 'system_path'.
// '_system_path'.
// @todo Consider abstracting this to a separate object.
if ($request->attributes->has('system_path')) {
// system_path never has leading or trailing slashes.
$path = '/' . $request->attributes->get('system_path');
if ($request->attributes->has('_system_path')) {
// _system_path never has leading or trailing slashes.
$path = '/' . $request->attributes->get('_system_path');
}
else {
// getPathInfo() always has leading slash, and might or might not have a
......
......@@ -30,7 +30,7 @@ public function finalMatch(RouteCollection $collection, Request $request) {
$context = new RequestContext();
$context->fromRequest($request);
$this->setContext($context);
return $this->match('/' . $request->attributes->get('system_path'));
return $this->match('/' . $request->attributes->get('_system_path'));
}
}
......@@ -50,8 +50,8 @@ public function build(array $attributes) {
// @todo This only works for legacy routes. Once node/% and forum/% are
// converted to the new router this code will need to be updated.
if (isset($attributes['drupal_menu_item'])) {
$item = $attributes['drupal_menu_item'];
if (isset($attributes['_drupal_menu_item'])) {
$item = $attributes['_drupal_menu_item'];
switch ($item['path']) {
case 'node/%':
......
......@@ -510,7 +510,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
public static function findRouteName($link_path) {
// Look up the route_name used for the given path.
$request = Request::create('/' . $link_path);
$request->attributes->set('system_path', $link_path);
$request->attributes->set('_system_path', $link_path);
try {
// Use router.dynamic instead of router, because router will call the
// legacy router which will call hook_menu() and you will get back to
......
......@@ -81,7 +81,7 @@ public function onRequest(GetResponseEvent $event) {
$user_data = $this->userData->get('overlay', $user->id(), 'enabled');
$use_overlay = !isset($user_data) || $user_data;
if (empty($mode) && user_access('access overlay') && $use_overlay) {
$current_path = $request->attributes->get('system_path');
$current_path = $request->attributes->get('_system_path');
// After overlay is enabled on the modules page, redirect to
// <front>#overlay=admin/modules to actually enable the overlay.
if (isset($_SESSION['overlay_enable_redirect']) && $_SESSION['overlay_enable_redirect']) {
......
......@@ -338,7 +338,7 @@ function testOutlinePathNoMatch() {
}
/**
* Confirms that system_path attribute overrides request path.
* Confirms that _system_path attribute overrides request path.
*/
function testSystemPathMatch() {
$connection = Database::getConnection();
......@@ -351,7 +351,7 @@ function testSystemPathMatch() {
$dumper->dump();
$request = Request::create('/path/one', 'GET');
$request->attributes->set('system_path', 'path/two');
$request->attributes->set('_system_path', 'path/two');
$routes_by_pattern = $provider->getRoutesByPattern('/path/two');
$routes = $provider->getRouteCollectionForRequest($request);
......
......@@ -2334,7 +2334,7 @@ function system_page_build(&$page) {
function system_custom_theme() {
if (drupal_container()->isScopeActive('request')) {
$request = drupal_container()->get('request');
$path = $request->attributes->get('system_path');
$path = $request->attributes->get('_system_path');
if (user_access('view the administration theme') && path_is_admin($path)) {
return config('system.theme')->get('admin');
}
......
......@@ -25,7 +25,7 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
public function onKernelRequestMaintenance(GetResponseEvent $event) {
$request = $event->getRequest();
// Allow access to menu_login_callback even if in maintenance mode.
if ($request->attributes->get('_maintenance') == MENU_SITE_OFFLINE && $request->attributes->get('system_path') == 'menu_login_callback') {
if ($request->attributes->get('_maintenance') == MENU_SITE_OFFLINE && $request->attributes->get('_system_path') == 'menu_login_callback') {
$request->attributes->set('_maintenance', MENU_SITE_ONLINE);
}
}
......
......@@ -23,7 +23,7 @@ class ThemeTestSubscriber implements EventSubscriberInterface {
*/
public function onRequest(GetResponseEvent $event) {
$request = $event->getRequest();
$current_path = $request->attributes->get('system_path');
$current_path = $request->attributes->get('_system_path');
if ($current_path == 'theme-test/request-listener') {
// First, force the theme registry to be rebuilt on this page request.
// This allows us to test a full initialization of the theme system in
......
......@@ -26,7 +26,7 @@ class MaintenanceModeSubscriber implements EventSubscriberInterface {
public function onKernelRequestMaintenance(GetResponseEvent $event) {
$request = $event->getRequest();
$site_status = $request->attributes->get('_maintenance');
$path = $request->attributes->get('system_path');
$path = $request->attributes->get('_system_path');
if ($site_status == MENU_SITE_OFFLINE) {
// If the site is offline, log out unprivileged users.
if ($GLOBALS['user']->isAuthenticated() && !user_access('access site in maintenance mode')) {
......
......@@ -102,7 +102,7 @@ public function ajaxView(Request $request) {
if ($view && $view->access($display_id)) {
// Fix the current path for paging.
if (!empty($path)) {
$request->attributes->set('system_path', $path);
$request->attributes->set('_system_path', $path);
}
// Add all $_POST data, because AJAX is always a post and many things,
......
......@@ -101,7 +101,7 @@ public function buildOptionsForm(&$form, &$form_state) {
}
public function getArgument() {
$path = $this->request->attributes->get('system_path');
$path = $this->request->attributes->get('_system_path');
if ($this->options['use_alias']) {
$path = $this->aliasManager->getPathAlias($path);
}
......
......@@ -39,7 +39,7 @@ public function testGetArgument() {
->disableOriginalConstructor()
->getMock();
$request = new Request(array(), array(), array('system_path' => 'test/example'));
$request = new Request(array(), array(), array('_system_path' => 'test/example'));
$alias_manager = $this->getMock('Drupal\Core\Path\AliasManagerInterface');
$alias_manager->expects($this->never())
->method('getPathAlias');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment