Use replaceWith, not replace, in #ajax form settings

Created on 30 May 2024, 8 months ago
Updated 16 July 2024, 6 months ago

Problem/Motivation

As per this Drupal change record β†’ , the method replace should not be used anymore, and replaceWith should be used instead. Both methods work identically before Drupal 10.3.0, but starting in this version, only replaceWith is supported.

Steps to reproduce

N/A

Proposed resolution

Replace all instances of replace in #ajax form settings with replaceWith.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

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

Merge Requests

Comments & Activities

  • Issue created by @maursilveira
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.5 + Environment: PHP 7.4 & MySQL 5.7
    last update 8 months ago
    9 pass
  • Status changed to Needs review 8 months ago
  • πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

    I've created a merge request with the adjustment.

  • Status changed to RTBC 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    I reviewed the MR, and it does just what the change record says. (Thanks for adding a link to the change record in the issue summary.) I also searched for other uses of 'method' => 'replace',, and I did not find any.

    The hard part is testing. From the issue description:

    Both methods work identically before Drupal 10.3.0, but starting in this version, only replaceWith is supported.

    Not quite. Starting with Drupal 10.3.0, replace generates a deprecation notice, which is not easy to test. I did it by hacking the line

            @trigger_error('Using "replace" as the method in #ajax property is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use "replaceWith" instead. See https://www.drupal.org/project/drupal/issues/3303557', E_USER_DEPRECATED);
    

    in Drupal\Core\Render\Element\RenderElementBase::preRenderAjaxForm(), removing the @ so that the error is not suppressed. After that change, I see a deprecation notice (debug level) in the logs each time I load the page at /admin/config/system/shield.

    When I make the change in the MR, I do not see any log messages when loading that page.

  • First commit to issue fork.
  • Pipeline finished with Skipped
    7 months ago
    #214159
  • Status changed to Fixed 7 months ago
  • πŸ‡ΊπŸ‡ΈUnited States japerry KVUO

    Verified that the deprecation notice and BC shim 'replaceWith' exists all the way back in Drupal 8, with the notice only being added in Drupal 10.3. Fixed.

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

Production build 0.71.5 2024