Unverified Commit a24f6682 authored by Alex Pott's avatar Alex Pott
Browse files

task: #3578374 Autowire core modules that require explicit configuration

By: dcam
By: godotislate
parent 57d2fe40
Loading
Loading
Loading
Loading
Loading
+9 −22
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
use Drupal\Core\Plugin\FilteredPluginManagerTrait;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\layout_discovery\Hook\LayoutDiscoveryThemeHooks;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
 * Provides a plugin manager for layouts.
@@ -23,29 +24,15 @@ class LayoutPluginManager extends DefaultPluginManager implements LayoutPluginMa

  use FilteredPluginManagerTrait;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Extension\ThemeHandlerInterface
   */
  protected $themeHandler;

  /**
   * LayoutPluginManager constructor.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations.
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
   *   Cache backend instance to use.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler to invoke the alter hook with.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ThemeHandlerInterface $theme_handler) {
  public function __construct(
    #[Autowire(service: 'container.namespaces')]
    \Traversable $namespaces,
    #[Autowire(service: 'cache.discovery')]
    CacheBackendInterface $cache_backend,
    ModuleHandlerInterface $module_handler,
    protected ThemeHandlerInterface $themeHandler,
  ) {
    parent::__construct('Plugin/Layout', $namespaces, $module_handler, LayoutInterface::class, Layout::class, 'Drupal\Core\Layout\Annotation\Layout');
    $this->themeHandler = $theme_handler;

    $type = $this->getType();
    $this->setCacheBackend($cache_backend, $type);
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ services:
    public: false
    class: \Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor
    decorates: html_response.attachments_processor
    arguments: ['@html_response.attachments_processor.big_pipe.inner', '@asset.resolver', '@config.factory', '@asset.css.collection_renderer', '@asset.js.collection_renderer', '@request_stack', '@renderer', '@module_handler', '@language_manager', '@file_url_generator']

  route_subscriber.no_big_pipe:
    class: Drupal\big_pipe\EventSubscriber\NoBigPipeRouteAlterSubscriber
+15 −9
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
use Drupal\Core\Render\HtmlResponse;
use Drupal\Core\Render\HtmlResponseAttachmentsProcessor;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;

/**
@@ -24,20 +25,25 @@
 */
class BigPipeResponseAttachmentsProcessor extends HtmlResponseAttachmentsProcessor {

  /**
   * The HTML response attachments processor service.
   *
   * @var \Drupal\Core\Render\AttachmentsResponseProcessorInterface
   */
  protected $htmlResponseAttachmentsProcessor;

  public function __construct(AttachmentsResponseProcessorInterface $html_response_attachments_processor, AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler, LanguageManagerInterface $language_manager, ?FileUrlGeneratorInterface $file_url_generator = NULL) {
  public function __construct(
    protected AttachmentsResponseProcessorInterface $htmlResponseAttachmentsProcessor,
    AssetResolverInterface $asset_resolver,
    ConfigFactoryInterface $config_factory,
    #[Autowire(service: 'asset.css.collection_renderer')]
    AssetCollectionRendererInterface $css_collection_renderer,
    #[Autowire(service: 'asset.js.collection_renderer')]
    AssetCollectionRendererInterface $js_collection_renderer,
    RequestStack $request_stack,
    RendererInterface $renderer,
    ModuleHandlerInterface $module_handler,
    LanguageManagerInterface $language_manager,
    ?FileUrlGeneratorInterface $file_url_generator = NULL,
  ) {
    if (!isset($file_url_generator)) {
      $file_url_generator = \Drupal::service('file_url_generator');
      @trigger_error('Constructing BigPipeResponseAttachmentsProcessor without a file url generator is deprecated in drupal:11.4.0 and the argument will be required in drupal:12.0.0. See https://www.drupal.org/project/drupal/issues/3366561', E_USER_DEPRECATED);
    }

    $this->htmlResponseAttachmentsProcessor = $html_response_attachments_processor;
    parent::__construct($asset_resolver, $config_factory, $css_collection_renderer, $js_collection_renderer, $request_stack, $renderer, $module_handler, $language_manager, $file_url_generator);
  }

+0 −1
Original line number Diff line number Diff line
@@ -7,7 +7,6 @@ services:
    autowire: true
  block_content.uuid_lookup:
    class: Drupal\block_content\BlockContentUuidLookup
    arguments: ['@cache.bootstrap', '@lock', '@entity_type.manager']
    tags:
      - { name: needs_destruction }
  Drupal\block_content\BlockContentUuidLookup: '@block_content.uuid_lookup'
+8 −19
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Cache\CacheCollector;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Lock\LockBackendInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

/**
 * A cache collector that caches IDs for block_content UUIDs.
@@ -20,26 +21,14 @@
 */
class BlockContentUuidLookup extends CacheCollector {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a BlockContentUuidLookup instance.
   *
   * @param \Drupal\Core\Cache\CacheBackendInterface $cache
   *   The cache backend.
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The lock backend.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(CacheBackendInterface $cache, LockBackendInterface $lock, EntityTypeManagerInterface $entity_type_manager) {
  public function __construct(
    #[Autowire(service: 'cache.bootstrap')]
    CacheBackendInterface $cache,
    #[Autowire(service: 'lock')]
    LockBackendInterface $lock,
    protected EntityTypeManagerInterface $entityTypeManager,
  ) {
    parent::__construct('block_content_uuid', $cache, $lock);
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
Loading