Problem/Motivation

When the parent implementation of \Drupal\Core\Template\Loader\ThemeRegistryLoader::getCacheKey() is called it causes deprecations on PHP 8.1 because it passes NULL to strlen().

Steps to reproduce

See tests on #3220021: [meta] Ensure compatibility of Drupal 9 with PHP 8.1 (as it evolves)

Proposed resolution

Re implement getCacheKey to do less work.

Remaining tasks

User interface changes

N/a

API changes

N/a

Data model changes

N/a

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
720 bytes

Here's the fix from the meta.

alexpott’s picture

Note this does not need to be fixed upstream because we override \Twig\Loader\FilesystemLoader::__construct() with the result that \Twig\Loader\FilesystemLoader::$rootPath is NULL. \Twig\Loader\FilesystemLoader::$rootPath is a private so we can't set it to an empty string.

longwave’s picture

+++ b/core/lib/Drupal/Core/Template/Loader/ThemeRegistryLoader.php
@@ -69,4 +69,17 @@ protected function findTemplate($name, $throw = TRUE) {
+    if (NULL === ($path = $this->findTemplate($name)) || FALSE === $path) {

I guess this is copied from upstream and fixed for our coding standards, but the rest of this class is all Drupal code - we don't use yoda conditions elsewhere, so should we refactor this to be more Drupally?

alexpott’s picture

Good point. I think all of that can more elegantly be written like this...

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Much cleaner!

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed f8f2752 and pushed to 9.3.x. Thanks!

  • larowlan committed f8f2752 on 9.3.x
    Issue #3239859 by alexpott, longwave: \Drupal\Core\Template\Loader\...

Status: Fixed » Closed (fixed)

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