class AjaxPageState

Same name in other branches
  1. 11.x core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php \Drupal\Core\StackMiddleware\AjaxPageState

Expands the compressed ajax_page_state query parameter into an array.

Hierarchy

Expanded class hierarchy of AjaxPageState

3 string references to 'AjaxPageState'
BigPipeTest::testBigPipeNoJs in core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
Tests BigPipe-delivered HTML responses when JavaScript is disabled.
core.services.yml in core/core.services.yml
core/core.services.yml
HistoryTest::testHistory in core/modules/history/tests/src/Functional/HistoryTest.php
Verifies that the history endpoints work.
1 service uses AjaxPageState
http_middleware.ajax_page_state in core/core.services.yml
Drupal\Core\StackMiddleware\AjaxPageState

File

core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php, line 13

Namespace

Drupal\Core\StackMiddleware
View source
class AjaxPageState implements HttpKernelInterface {
    
    /**
     * Constructs a new AjaxPageState instance.
     *
     * @param \Symfony\Component\HttpKernel\HttpKernelInterface $httpKernel
     *   The wrapped HTTP kernel.
     */
    public function __construct(HttpKernelInterface $httpKernel) {
    }
    
    /**
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
        if ($type === static::MAIN_REQUEST) {
            if ($request->request
                ->has('ajax_page_state')) {
                $request->request
                    ->set('ajax_page_state', $this->parseAjaxPageState($request->request
                    ->all('ajax_page_state')));
            }
            elseif ($request->query
                ->has('ajax_page_state')) {
                $request->query
                    ->set('ajax_page_state', $this->parseAjaxPageState($request->query
                    ->all('ajax_page_state')));
            }
        }
        return $this->httpKernel
            ->handle($request, $type, $catch);
    }
    
    /**
     * Parse the ajax_page_state variable in the request.
     *
     * Decompresses the libraries array key.
     *
     * @param array $ajax_page_state
     *   An array of query parameters, where the libraries parameter is compressed.
     *
     * @return array
     */
    private function parseAjaxPageState(array $ajax_page_state) : array {
        $ajax_page_state['libraries'] = UrlHelper::uncompressQueryParameter($ajax_page_state['libraries']);
        return $ajax_page_state;
    }

}

Members

Title Sort descending Modifiers Object type Summary
AjaxPageState::handle public function
AjaxPageState::parseAjaxPageState private function Parse the ajax_page_state variable in the request.
AjaxPageState::__construct public function Constructs a new AjaxPageState instance.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.