Handle renderPlain() deprecation

Created on 23 July 2024, 5 months ago
Updated 18 August 2024, 4 months ago

Due to https://www.drupal.org/node/3407994 , we need to figure out the best way to handle the renderPlain() call that will likely be committed as part of Smart Trim Tokens for text with summary fields Needs review .

If 2.1.x of Smart Trim only supported 10+, then we could use the Deprecation Helper. But, since 2.1.x currently says it supports 8+, we have a problem.

So, I think the first step is to see if we're actually lying about 2.1.x and whether or not it actually runs on 8.x or 9.x.

Once we know this, then we can figure out the next step.

-mike

📌 Task
Status

Fixed

Version

2.1

Component

Code

Created by

🇺🇸United States ultimike Florida, USA

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

Comments & Activities

  • Issue created by @ultimike
  • First commit to issue fork.
  • 🇮🇪Ireland lostcarpark

    The tests for "previous_major" are run against Drupal 9.5, so that is the oldest version I would confidently say Smart Trim will work against.

    I added the following to another module that wasn't willing to drop D9 support yet:

        if (version_compare(\Drupal::VERSION, '10.1.0') >= 0) {
          // Drupal 10.1 or later, use DeprecationHelper.
          // Note, put back named parameters when we drop support for Drupal 9.5.
          $output = DeprecationHelper::backwardsCompatibleCall(
            \Drupal::VERSION,
            '10.3',
            fn() => \Drupal::service('renderer')->renderInIsolation($build),
            fn() => \Drupal::service('renderer')->renderPlain($build),
          );
        }
        else {
          // Remove when we drop support for < Drupal 10.1.
          // @phpstan-ignore-next-line
          $output = \Drupal::service('renderer')->renderPlain($build);
        }
    

    It's a little bit hacky, especially since D9 needs to support PHP 7.4, so I had to remove named parameters from the DeprecationHelper. Hopefully we'll drop D9 support and remove the if() wrapper.

  • 🇺🇸United States markie Albuquerque, NM

    Merged in an update that dropped <9.5 support for the next release.

  • 🇮🇳India ankitv18

    Hi,
    I've updated the MR with replacing the logic of implementing renderPlain deprecation with the below code block.

    if (method_exists(RendererInterface::class, 'renderPlain')) {
            // @phpstan-ignore-next-line as it is deprecated in D10.3 and removed from D12.
            $field_output_renderer = \Drupal::service('renderer')->renderPlain($field_output);
          }
          else {
            $field_output_renderer = \Drupal::service('renderer')->renderInIsolation($field_output);
          }
    

    Pros:

    1. Support below D10
    2. Handles both renderPlain and renderInIsolation without deprecationHelper class.

    cc: @markie @ultimike

  • Status changed to Fixed 5 months ago
  • 🇺🇸United States ultimike Florida, USA

    Thanks @lostcarpark and @ankitv18 - I'm closing this issue as the fix is part of Smart Trim Tokens for text with summary fields Needs review .

    -mike

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

Production build 0.71.5 2024