- Issue created by @lostcarpark
- Assigned to sarwan_verma
- Issue was unassigned.
- Status changed to Needs review
4 months ago 6:17am 17 July 2024 - 🇮🇳India sarwan_verma
Hi @lostcarpark,
I have resolved the RendererInterface::renderInIsolation() issue and created MR!21.
Kindly review and verify.
Thanks!
- 🇮🇪Ireland lostcarpark
Thank you for your work on this.
The tests are passing now for current and next_major.
Unfortunately, they are failing for previous_minor and previous_major. This is because
renderInIsolation
was only introduced in Drupal 10.3.For previous_minor, we could use DeprecationHelper as follows:
$output = DeprecationHelper::backwardsCompatibleCall( currentVersion: \Drupal::VERSION, deprecatedVersion: '10.3', currentCallable: fn() => \Drupal::service('renderer')->renderInIsolation($build), deprecatedCallable: fn() => \Drupal::service('renderer')->renderPlain($build), );
Unfortunately, DeprecationHelper was only introduced in 10.1, so for the moment at least, we'll need additional measures to keep support for Drupal 9.5. I think we need to support this at least while automated tests run against it. I think we could handle all supported versions with:
if (version_compare(\Drupal::VERSION, '10.1.0') >= 0) { // Drupal 10.1 or later, use DeprecationHelper. $output = DeprecationHelper::backwardsCompatibleCall( currentVersion: \Drupal::VERSION, deprecatedVersion: '10.3', currentCallable: fn() => \Drupal::service('renderer')->renderInIsolation($build), deprecatedCallable: 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); }
Please update the fix and see if tests will pass.
- 🇮🇪Ireland lostcarpark
I learned a much cleaner fix from @ankitv18:
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); }
- Status changed to Fixed
3 months ago 11:34am 31 August 2024 Automatically closed - issue fixed for 2 weeks with no activity.