Use replaceWith, not replace, in #ajax form settings

Created on 30 May 2024, 26 days ago
Updated 31 May 2024, 26 days 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

RTBC

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 26 days ago
    9 pass
  • Status changed to Needs review 26 days ago
  • πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

    I've created a merge request with the adjustment.

  • Status changed to RTBC 26 days 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.

Production build 0.69.0 2024