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 #2782455: Smart Trim Tokens for text with summary fields.

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

Issue fork smart_trim-3463405

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ultimike created an issue. See original summary.

sarwan_verma made their first commit to this issue’s fork.

lostcarpark’s picture

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.

markie’s picture

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

ankitv18’s picture

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

ultimike’s picture

Status: Active » Fixed

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

-mike

Status: Fixed » Closed (fixed)

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