function Drupal::request
Same name in other branches
- 9 core/lib/Drupal.php \Drupal::request()
- 8.9.x core/lib/Drupal.php \Drupal::request()
- 10 core/lib/Drupal.php \Drupal::request()
Retrieves the currently active request object.
Note: The use of this wrapper in particular is especially discouraged. Most code should not need to access the request directly. Doing so means it will only function when handling an HTTP request, and will require special modification or wrapping when run from a command line tool, from certain queue processors, or from automated tests.
If code must access the request, it is considerably better to register an object with the Service Container and give it a setRequest() method that is configured to run when the service is created. That way, the correct request object can always be provided by the container and the service can still be unit tested.
If this method must be used, never save the request object that is returned. Doing so may lead to inconsistencies as the request object is volatile and may change at various times, such as during a subrequest.
Return value
\Symfony\Component\HttpFoundation\Request The currently active request object.
37 calls to Drupal::request()
- batch_process in core/
includes/ form.inc - Processes the batch.
- BigPipeHooks::pageAttachments in core/
modules/ big_pipe/ src/ Hook/ BigPipeHooks.php - Implements hook_page_attachments().
- BigPipeTestHooks::pageTop in core/
modules/ big_pipe/ tests/ modules/ big_pipe_test/ src/ Hook/ BigPipeTestHooks.php - Implements hook_page_top().
- big_pipe_test_page_top in core/
modules/ big_pipe/ tests/ modules/ big_pipe_test/ big_pipe_test.module - Implements hook_page_top().
- BlockViewBuilderTest::testBlockViewBuilderBuildAlter in core/
modules/ block/ tests/ src/ Kernel/ BlockViewBuilderTest.php - Tests block build altering.
File
-
core/
lib/ Drupal.php, line 268
Class
- Drupal
- Static Service Container wrapper.
Code
public static function request() {
return static::getContainer()->get('request_stack')
->getCurrentRequest();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.