Use httpMethod instead of type for AJAX get/post request property

Created on 7 April 2023, about 1 year ago
Updated 26 April 2023, about 1 year ago

Problem/Motivation

See #956186-189: Allow AJAX to use GET requests โ†’ .

'method' has been in use for a long time. The original patch used 'type', but maybe we could change that to 'httpMethod'. If we make the change before 10.1.x, it won't be an API change.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

๐Ÿ“Œ Task
Status

Fixed

Version

10.1 โœจ

Component
Ajaxย  โ†’

Last updated about 1 hour ago

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

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

Comments & Activities

  • Issue created by @catch
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany geek-merlin Freiburg, Germany

    +1. Way more intuitive.

  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    Untested patch. Couple of things I noticed:

    - type was probably originally chosen because jQuery.ajax used 'type' for GET/POST.

    - Since jQuery 1.9, it allows method, which type is a direct alias/bc for, although ajax.js relies on 'type' still, likely just because it's never been updated.

    - as lauriii points out in the other issue, we can't use 'method' because we already use that for replacements.

    So... trying httpMethod, I changed the one reference to jQuery AJAX 'type' to 'method' too here since that makes things slightly more consistent.

    Passed through my mind that we should consider renaming 'method' to 'replaceMethod' in the AJAX API too, different issue if we wanted to do that though.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Throwing my hat into the bikeshed: these are commonly referred to as HTTP verbs, so if we can't use method what about verb?

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany geek-merlin Freiburg, Germany

    > so if we can't use method what about verb?
    Good point. I would've had to scratch my head what this means though. So while technically more correct, maybe not so intuitive for some.

    Also, i'd prefer httpMethod over method (and verb), because it includes the context, so its meaning is not dependent on additional context.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bkosborne New Jersey, USA

    +1 for httpMethod over verb. I appreciate the verbosity

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium Wim Leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    โ€œHTTP methodโ€ is more explicit than โ€œmethodโ€ or โ€œverbโ€ to my ears too.

    Plus, itโ€™s consistent with how Symfony refers to it in its route definitions.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    If I got a vote I like httpMethod.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK
    +++ b/core/misc/ajax.js
    @@ -325,12 +325,12 @@
    +      const httpMethod = $linkElement.data('ajax-httpMethod');
    

    As a data attribute wouldn't this become data-http-method? Data attribute usually use kebab-case instead of snakeCase.

    I also don't see any test coverage for this :(

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Just to keep it moving, sending to NW for test coverage.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom catch

    I don't think we should add test coverage for a direct rename, there is a lot of implicit coverage of the AJAX API via views but not much explicit. Leaving needs work for #9 though.

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,300 pass
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    Addressed the feedback and updated the comments.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK
    +++ b/core/misc/ajax.js
    @@ -325,12 +325,12 @@
            * In case of setting custom ajax type for link we rewrite ajax.type.
    

    I think this comment needs updating a bit given one part of it is no longer called "type". This comment didn't really add much anyway, not sure it is needed, although it is perhaps the only documentation for this feature.

    I am still concerned there is no test coverage for data-ajax-type / data-ajax-http-method but I suppose that shouldn't hold this up otherwise we have to do a deprecation dance and so that can be deferred to a followup.

  • Status changed to Needs review about 1 year ago
  • last update about 1 year ago
    29,300 pass
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    This should address #13.

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Opened ๐Ÿ“Œ Add test coverage for data-ajax-http-method attribute Active as a follow up.

  • Status changed to Fixed about 1 year ago
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Committing this now so it can get in before the alpha release.

    Committed and pushed cb77884135 to 10.1.x. Thanks!

    Will update the change record to mention the new property name.

  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom longwave UK

    Updated https://www.drupal.org/node/3193798 โ†’ and linked it to this issue.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024