Issue #1843084 by effulgentsia, Crell: Convert user/register to Route.

8.0.x
catch 2012-11-22 10:56:57 +00:00
parent 553ed06a17
commit e9e8c8f854
7 changed files with 96 additions and 11 deletions

View File

@ -10,6 +10,7 @@ namespace Drupal\Core\EventSubscriber;
use Drupal\Core\Language\LanguageManager;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
@ -41,6 +42,10 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
* The event to process.
*/
public function onRespond(FilterResponseEvent $event) {
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}
$response = $event->getResponse();
// Set the X-UA-Compatible HTTP header to force IE to use the most recent

View File

@ -52,7 +52,7 @@ class HtmlPageController implements ContainerAwareInterface {
// require an _internal route. For examples, see:
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing/internal.xml
// https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/InternalController.php
$attributes = $request->attributes;
$attributes = clone $request->attributes;
$controller = $_content;
// We need to clean off the derived information and such so that the
@ -62,8 +62,12 @@ class HtmlPageController implements ContainerAwareInterface {
$response = $this->container->get('http_kernel')->forward($controller, $attributes->all(), $request->query->all());
$page_content = $response->getContent();
// For successful (HTTP status 200) responses, decorate with blocks.
if ($response->isOk()) {
$page_content = $response->getContent();
$response = new Response(drupal_render_page($page_content));
}
return new Response(drupal_render_page($page_content));
return $response;
}
}

View File

@ -56,7 +56,21 @@ class PathMatcher implements InitialMatcherInterface {
*/
public function matchRequestPartial(Request $request) {
$path = rtrim($request->getPathInfo(), '/');
// 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'.
// @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');
}
else {
// getPathInfo() always has leading slash, and might or might not have a
// trailing slash.
$path = rtrim($request->getPathInfo(), '/');
}
$parts = array_slice(array_filter(explode('/', $path)), 0, MatcherDumper::MAX_PARTS);

View File

@ -299,4 +299,27 @@ class PathMatcherTest extends UnitTestBase {
}
/**
* Confirms that system_path attribute overrides request path.
*/
function testSystemPathMatch() {
$connection = Database::getConnection();
$matcher = new PathMatcher($connection, 'test_routes');
$this->fixtures->createTables($connection);
$dumper = new MatcherDumper($connection, 'test_routes');
$dumper->addRoutes($this->fixtures->sampleRouteCollection());
$dumper->dump();
$request = Request::create('/path/one', 'GET');
$request->attributes->set('system_path', 'path/two');
$routes = $matcher->matchRequestPartial($request);
foreach ($routes as $route) {
$this->assertEqual($route->getPattern(), '/path/two', 'Found path has correct pattern');
}
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @file
* Contains of Drupal\user\UserRouteController.
*/
namespace Drupal\user;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* Returns responses for User module routes.
*/
class UserRouteController extends ContainerAware {
/**
* Returns the user registration form.
*
* @return array
* A renderable array containing the user registration form.
*/
public function register() {
// @todo Remove once access control is integrated with new routing system:
// http://drupal.org/node/1793520.
if (!user_register_access()) {
throw new AccessDeniedHttpException();
}
$account = entity_create('user', array());
return entity_get_form($account, 'register');
}
}

View File

@ -1070,11 +1070,6 @@ function user_is_logged_in() {
return (bool) $GLOBALS['user']->uid;
}
function user_register() {
$account = entity_create('user', array());
return entity_get_form($account, 'register');
}
function user_register_access() {
return user_is_anonymous() && (config('user.settings')->get('register') != USER_REGISTER_ADMINISTRATORS_ONLY);
}
@ -1160,9 +1155,14 @@ function user_menu() {
$items['user/register'] = array(
'title' => 'Create new account',
'page callback' => 'user_register',
'access callback' => 'user_register_access',
'type' => MENU_LOCAL_TASK,
// @todo This route is now declared in user.routing.yml, so the below are
// only needed for drupal_valid_path(). Without a non-empty (but not
// necessarily valid) page callback, _menu_router_build() overrides the
// access callback to 0. Remove once drupal_valid_path works with the new
// routing system: http://drupal.org/node/1793520.
'page callback' => 'NOT_USED',
'access callback' => 'user_register_access',
);
$items['user/password'] = array(

View File

@ -0,0 +1,4 @@
user_register:
pattern: '/user/register'
defaults:
_content: '\Drupal\user\UserRouteController::register'