Verified Commit a30c38e4 authored by Dave Long's avatar Dave Long
Browse files

Issue #3556130 by alexpott: ThemeEngine BC layer is broken - ServiceLocator != Container

parent 598aaf25
Loading
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -11,10 +11,9 @@
use Drupal\Core\Template\Attribute;
use Drupal\Core\Template\AttributeHelper;
use Drupal\Core\Utility\CallableResolver;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\DependencyInjection\Attribute\AutowireLocator;
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
use Symfony\Contracts\Service\ServiceCollectionInterface;

/**
 * Provides the default implementation of a theme manager.
@@ -64,7 +63,7 @@ public function __construct(
    protected ModuleHandlerInterface $moduleHandler,
    protected CallableResolver $callableResolver,
    #[AutowireLocator('theme_engine', 'engine_name')]
    protected ContainerInterface $themeEngines,
    protected ServiceCollectionInterface $themeEngines,
    protected ?KeyValueFactoryInterface $keyValueFactory = NULL,
    #[Autowire(service: 'cache.bootstrap')]
    protected ?CacheBackendInterface $cache = NULL,
@@ -660,7 +659,7 @@ public function getDefaultTemplateVariables(): array {
   * {@inheritdoc}
   */
  public function getThemeEngine(string $name): ?ThemeEngineInterface {
    return $this->themeEngines->get($name, SymfonyContainerInterface::NULL_ON_INVALID_REFERENCE);
    return $this->themeEngines->has($name) ? $this->themeEngines->get($name) : NULL;
  }

}
+35 −0
Original line number Diff line number Diff line
<?php

declare(strict_types=1);

namespace Drupal\Tests\system\Functional\Theme;

use Drupal\Tests\BrowserTestBase;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;

/**
 * Tests theme engine BC layer.
 */
#[Group('Theme')]
#[RunTestsInSeparateProcesses]
#[IgnoreDeprecations]
class BcEngineTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'test_theme_engine_theme';

  /**
   * Tests that .engine theme engines still work.
   */
  public function testPage(): void {
    $this->expectDeprecation('Drupal\Core\Theme\ActiveTheme::getOwner() is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Theme engines are now tagged services instead of extensions. See https://www.drupal.org/node/3547356');
    $this->expectDeprecation('Using .engine files for theme engines is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Convert test_theme_engine.engine to a service. See https://www.drupal.org/node/3547356');
    $this->drupalGet('');
    $this->assertSession()->statusCodeEquals(200);
  }

}
+3 −0
Original line number Diff line number Diff line
@@ -31,6 +31,9 @@ protected function setUp(): void {
  public function testThemeEngineDeprecation(): void {
    $this->expectDeprecation('Using .engine files for theme engines is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Convert test_theme_engine.engine to a service. See https://www.drupal.org/node/3547356');
    \Drupal::service('theme.initialization')->initTheme('test_theme_engine_theme');
    // Ensure that \Drupal\Core\Theme\ThemeManager::getThemeEngine() does not
    // error when the theme engine service is not found.
    $this->assertNull(\Drupal::service('theme.manager')->getThemeEngine('test_theme_engine_theme'));
  }

}