Unverified Commit 70175bc0 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3215611 by alexpott, longwave: Service deprecations are only triggered...

Issue #3215611 by alexpott, longwave: Service deprecations are only triggered on container build,not ::get()
parent ff8ead85
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -128,6 +128,11 @@ public function __construct(array $container_definition = []) {
   * {@inheritdoc}
   */
  public function get($id, $invalid_behavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) {
    if ($this->hasParameter('_deprecated_service_list')) {
      if ($deprecation = $this->getParameter('_deprecated_service_list')[$id] ?? '') {
        @trigger_error($deprecation, E_USER_DEPRECATED);
      }
    }
    if (isset($this->aliases[$id])) {
      $id = $this->aliases[$id];
    }
+2 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass;
use Drupal\Core\DependencyInjection\Compiler\BackendCompilerPass;
use Drupal\Core\DependencyInjection\Compiler\CorsCompilerPass;
use Drupal\Core\DependencyInjection\Compiler\DeprecatedServicePass;
use Drupal\Core\DependencyInjection\Compiler\GuzzleMiddlewarePass;
use Drupal\Core\DependencyInjection\Compiler\ContextProvidersPass;
use Drupal\Core\DependencyInjection\Compiler\ProxyServicesPass;
@@ -98,6 +99,7 @@ public function register(ContainerBuilder $container) {
    $container->addCompilerPass(new PluginManagerPass());

    $container->addCompilerPass(new DependencySerializationTraitPass());
    $container->addCompilerPass(new DeprecatedServicePass());
  }

  /**
+33 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
 * Sets the _deprecated_service_list parameter.
 *
 * @see \Drupal\Component\DependencyInjection\Container::get()
 */
class DeprecatedServicePass implements CompilerPassInterface {

  /**
   * {@inheritdoc}
   */
  public function process(ContainerBuilder $container) {
    $deprecated_services = [];
    foreach ($container->getDefinitions() as $service_id => $definition) {
      if ($definition->isDeprecated()) {
        $deprecated_services[$service_id] = $definition->getDeprecationMessage($service_id);
      }
    }
    foreach ($container->getAliases() as $service_id => $definition) {
      if ($definition->isDeprecated()) {
        $deprecated_services[$service_id] = $definition->getDeprecationMessage($service_id);
      }
    }
    $container->setParameter('_deprecated_service_list', $deprecated_services);
  }

}
+7 −0
Original line number Diff line number Diff line
services:
  deprecation_test.service:
    class: Drupal\deprecation_test\Deprecation\FixtureDeprecatedClass
    deprecated: The "%service_id%" service is deprecated in drupal:9.0.0 and is removed from drupal:20.0.0. This is a test.
  deprecation_test.alias:
    alias: deprecation_test.service
    deprecated: The "%alias_id%" alias is deprecated in drupal:9.0.0 and is removed from drupal:20.0.0. This is a test.
+2 −2
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ public function testExtensionCompatibilityChange(array $correct_info, array $bre
    if ($extension_type === 'theme') {
      $base_info['base theme'] = FALSE;
    }
    $folder_path = \Drupal::service('site.path') . "/{$extension_type}s/$extension_machine_name";
    $folder_path = \Drupal::getContainer()->getParameter('site.path') . "/{$extension_type}s/$extension_machine_name";
    $file_path = "$folder_path/$extension_machine_name.info.yml";
    mkdir($folder_path, 0777, TRUE);
    file_put_contents($file_path, Yaml::encode($base_info + $correct_info));
@@ -380,7 +380,7 @@ public function testMissingExtension($extension_type) {
    if ($extension_type === 'theme') {
      $extension_info['base theme'] = FALSE;
    }
    $folder_path = \Drupal::service('site.path') . "/{$extension_type}s/$extension_machine_name";
    $folder_path = \Drupal::getContainer()->getParameter('site.path') . "/{$extension_type}s/$extension_machine_name";
    $file_path = "$folder_path/$extension_machine_name.info.yml";
    mkdir($folder_path, 0777, TRUE);
    file_put_contents($file_path, Yaml::encode($extension_info));
Loading