Prevent _wrapper_format and ajax_form parameters from bleeding through to generated URLs

Created on 11 June 2015, over 9 years ago
Updated 30 January 2024, 10 months ago

Follow-up to #2263569: Bypass form caching by default for forms using #ajax. β†’

Problem/Motivation

- The added request parameters bleed into links.
- E.g. right-clicking on a newly loaded pager link, returns AJAX

Proposed resolution

- Remove internal request parameters from the Request object as soon as possible, store them somewhere else, so that later subscribers can still access them.

( Service? Request->param() *brrr*? ... )

Remaining tasks

- Stalk Crell :-D
- Discuss

User interface changes

API changes

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
RoutingΒ  β†’

Last updated 2 days ago

Created by

πŸ‡©πŸ‡ͺGermany Fabianx

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡΅πŸ‡±Poland sayco ToruΕ„

    My issue is partially related to the topic, but still, I'm here because of that piece of code

          // Remove all of this stuff from the query of the request so it doesn't
          // end up in pagers and tablesort URLs.
          // @todo Remove this parsing once these are removed from the request in
          //   https://www.drupal.org/node/2504709.
          foreach ([
            'view_name',
            'view_display_id',
            'view_args',
            'view_path',
            'view_dom_id',
            'pager_element',
            'view_base_path',
            AjaxResponseSubscriber::AJAX_REQUEST_PARAMETER,
            FormBuilderInterface::AJAX_FORM_REQUEST,
            MainContentViewSubscriber::WRAPPER_FORMAT,
          ] as $key) {
            $request->query->remove($key);
            $request->request->remove($key);
          }
    

    I really need access to the original data from the request (as for many of you my $form['#action'] is incorrect).

    My proposal to sort this out is to clone the request object and push it to the request stack.
    Thanks to that we can still get the main/master request and the current one.

    In my case, I just simply wrote the Route Subscriber and alter the `views.ajax`
    route with a custom controller.
    In the controller I simply do the following:

      /**
       * {@inheritdoc}
       */
      public function ajaxView(Request $request) {
        $request = clone($request);
        $this->requestStack->push($request);
        
        return parent::ajaxView($request);
      }
    

    The view is working without any issues (at least seem to be working fine), and I'm able to now do whatever I want with the data from the main request by

     $request = $this->requestStack->getMainRequest();
    

    I hope this workaround will somehow help you with finding the right solution.

  • πŸ‡¬πŸ‡§United Kingdom catch

    πŸ› ajax_page_state leaks through request in Views Ajax Needs work may have changed things here a bit.

Production build 0.71.5 2024