Commit dec3e5c0 authored by alexpott's avatar alexpott

Issue #1987728 by Niklas Fiekas, vijaycs85: Convert language_test_subrequest()...

Issue #1987728 by Niklas Fiekas, vijaycs85: Convert language_test_subrequest() to a new style controller.
parent 94b0b70f
......@@ -99,38 +99,3 @@ function language_test_store_language_negotiation() {
function language_test_language_negotiation_method($languages) {
return 'it';
}
/**
* Implements hook_menu().
*/
function language_test_menu() {
$items = array();
$items['language_test/subrequest'] = array(
'page callback' => 'language_test_subrequest',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Page callback. Uses a subrequest to retrieve the 'user' page.
*/
function language_test_subrequest() {
$request = Request::createFromGlobals();
$server = $request->server->all();
if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
// We need this for when the test is executed by run-tests.sh.
// @todo Remove this once run-tests.sh has been converted to use a Request
// object.
$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'];
$base_path = ltrim($server['REQUEST_URI'], '/');
}
else {
$base_path = $request->getBasePath();
}
$subrequest = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), array(), $server);
return Drupal::service('http_kernel')->handle($subrequest, HttpKernelInterface::SUB_REQUEST);
}
......@@ -11,3 +11,10 @@ language_test_theme_link_active_class:
_content: '\Drupal\language_test\Controller\LanguageTestController::themeLinkActiveClass'
requirements:
_access: 'TRUE'
language_test_subrequest:
pattern: '/language_test/subrequest'
defaults:
_controller: '\Drupal\language_test\Controller\LanguageTestController::testSubRequest'
requirements:
_access: 'TRUE'
......@@ -9,17 +9,36 @@
use Drupal\Core\Controller\ControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/**
* Controller routines for language_test routes.
*/
class LanguageTestController implements ControllerInterface {
/**
* The HTTP kernel service.
*
* @var \Symfony\Component\HttpKernel\HttpKernelInterface
*/
protected $httpKernel;
/**
* Constructs a new LanguageTestController object.
*
* @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
* An HTTP kernel.
*/
public function __construct(HttpKernelInterface $httpKernel) {
$this->httpKernel = $httpKernel;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static();
return new static($container->get('http_kernel'));
}
/**
......@@ -110,4 +129,27 @@ public function lActiveClass() {
);
}
/**
* Uses a sub request to retrieve the 'user' page.
*
* @return \Symfony\Component\HttpFoundation\Response
* The kernels response to the sub request.
*/
public function testSubRequest() {
$request = Request::createFromGlobals();
$server = $request->server->all();
if (basename($server['SCRIPT_FILENAME']) != basename($server['SCRIPT_NAME'])) {
// We need this for when the test is executed by run-tests.sh.
// @todo Remove this once run-tests.sh has been converted to use a Request
// object.
$server['SCRIPT_FILENAME'] = $server['SCRIPT_NAME'];
$base_path = ltrim($server['REQUEST_URI'], '/');
}
else {
$base_path = $request->getBasePath();
}
$sub_request = Request::create($base_path . '/user', 'GET', $request->query->all(), $request->cookies->all(), array(), $server);
return $this->httpKernel->handle($sub_request, HttpKernelInterface::SUB_REQUEST);
}
}
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