Verified Commit d60d2ce1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3441392 by Binoli Lalani, smustgrave, andypost, quietone,...

Issue #3441392 by Binoli Lalani, smustgrave, andypost, quietone, pradhumanjain2311, longwave, catch: Removed deprecated code in Render system
parent 65e7a1ef
Loading
Loading
Loading
Loading
Loading
+2 −12
Original line number Diff line number Diff line
@@ -130,9 +130,8 @@ public function jsonSerialize(): string {
   *   An associative array of replacements. Each array key should be the same
   *   as a placeholder in $string. The corresponding value should be a string
   *   or an object that implements \Drupal\Component\Render\MarkupInterface.
   *   Null args[] values are deprecated in Drupal 9.5 and will fail in
   *   Drupal 11.0. The value replaces the placeholder in $string. Sanitization
   *   and formatting will be done before replacement. The type of sanitization
   *   The args[] value replaces the placeholder in $string. Sanitization and
   *   formatting will be done before replacement. The type of sanitization
   *   and formatting depends on the first character of the key:
   *   - @variable: When the placeholder replacement value is:
   *     - A string, the replaced value in the returned string will be sanitized
@@ -194,15 +193,6 @@ public function jsonSerialize(): string {
  protected static function placeholderFormat($string, array $args) {
    // Transform arguments before inserting them.
    foreach ($args as $key => $value) {
      if (is_null($value)) {
        // It's probably a bug to provide a null value for the placeholder arg,
        // and in D11 this will no longer be allowed. When this trigger_error
        // is removed, also remove isset $value checks inside the switch{}
        // below.
        // phpcs:ignore Drupal.Semantics.FunctionTriggerError
        @trigger_error(sprintf('Deprecated NULL placeholder value for key (%s) in: "%s". This will throw a PHP error in drupal:11.0.0. See https://www.drupal.org/node/3318826', (string) $key, (string) $string), E_USER_DEPRECATED);
        $value = '';
      }
      switch ($key[0]) {
        case '@':
          // Escape if the value is not an object from a class that implements
+0 −45
Original line number Diff line number Diff line
<?php

namespace Drupal\Core\Render\Element;

use Drupal\Core\Render\Attribute\RenderElement;

/**
 * Provides a render element for adding Ajax to a render element.
 *
 * Holds an array whose values control the Ajax behavior of the element.
 *
 * @ingroup ajax
 *
 * @deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Return an
 *   \Drupal\Core\Ajax\AjaxResponse instead.
 *
 * @see https://www.drupal.org/node/3068104
 */
#[RenderElement('ajax')]
class Ajax extends RenderElementBase {

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    @trigger_error('\Drupal\Core\Render\Element\Ajax is deprecated in drupal:10.1.0 and is removed from drupal:11.0.0. Return an \Drupal\Core\Ajax\AjaxResponse instead. See https://www.drupal.org/node/3068104', E_USER_DEPRECATED);
  }

  /**
   * {@inheritdoc}
   */
  public function getInfo() {
    // By default, we don't want Ajax commands being rendered in the context of
    // an HTML page, so we don't provide defaults for #theme or #theme_wrappers.
    // However, modules can set these properties (for example, to provide an
    // HTML debugging page that displays rather than executes Ajax commands).
    return [
      '#header' => TRUE,
      '#commands' => [],
      '#error' => NULL,
    ];
  }

}
+0 −6
Original line number Diff line number Diff line
@@ -372,12 +372,6 @@ public static function preRenderAjaxForm($element) {
        $settings['options']['query'][FormBuilderInterface::AJAX_FORM_REQUEST] = TRUE;
      }

      // @todo Legacy support. Remove in Drupal 8.
      if (isset($settings['method']) && $settings['method'] == 'replace') {
        @trigger_error('Using "replace" as the method in #ajax property is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use "replaceWith" instead. See https://www.drupal.org/project/drupal/issues/3303557', E_USER_DEPRECATED);
        $settings['method'] = 'replaceWith';
      }

      // Convert \Drupal\Core\Url object to string.
      if (isset($settings['url']) && $settings['url'] instanceof Url) {
        $url = $settings['url']->setOptions($settings['options'])->toString(TRUE);
+9 −35
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@
namespace Drupal\Core\Render;

use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
use Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
@@ -25,15 +23,6 @@
 */
class ElementInfoManager extends DefaultPluginManager implements ElementInfoManagerInterface {

  use DeprecatedServicePropertyTrait;

  /**
   * Defines deprecated injected properties.
   *
   * @var array
   */
  protected array $deprecatedProperties = ['cacheTagInvalidator' => 'cache_tags.invalidator'];

  /**
   * Stores the available element information.
   *
@@ -41,20 +30,6 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana
   */
  protected $elementInfo;

  /**
   * The theme manager.
   *
   * @var \Drupal\Core\Theme\ThemeManagerInterface
   */
  protected $themeManager;

  /**
   * The theme handler.
   *
   * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
   */
  protected $themeHandler;

  /**
   * Constructs an ElementInfoManager object.
   *
@@ -63,22 +38,21 @@ class ElementInfoManager extends DefaultPluginManager implements ElementInfoMana
   *   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\ThemeHandlerInterface|\Drupal\Core\Cache\CacheTagsInvalidatorInterface $theme_handler
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $themeHandler
   *   The theme handler.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
   * @param \Drupal\Core\Theme\ThemeManagerInterface $themeManager
   *   The theme manager.
   */
  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ThemeHandlerInterface|CacheTagsInvalidatorInterface $theme_handler, ModuleHandlerInterface $module_handler, ThemeManagerInterface $theme_manager) {
  public function __construct(
    \Traversable $namespaces,
    CacheBackendInterface $cache_backend,
    protected ThemeHandlerInterface $themeHandler,
    ModuleHandlerInterface $module_handler,
    protected ThemeManagerInterface $themeManager,
  ) {
    $this->setCacheBackend($cache_backend, 'element_info');
    $this->themeManager = $theme_manager;
    if ($theme_handler instanceof CacheTagsInvalidatorInterface) {
      @trigger_error('Calling ' . __METHOD__ . '() with the $cache_tag_invalidator argument is deprecated in drupal:10.2.0 and will be removed in drupal:11.0.0. Pass $theme_handler instead. See https://www.drupal.org/node/3355227', E_USER_DEPRECATED);
      $theme_handler = \Drupal::service('theme_handler');
    }
    $this->themeHandler = $theme_handler;

    parent::__construct('Element', $namespaces, $module_handler, 'Drupal\Core\Render\Element\ElementInterface', RenderElement::class, 'Drupal\Core\Render\Annotation\RenderElement');
    $this->alterInfo('element_plugin');
  }
+16 −60
Original line number Diff line number Diff line
@@ -33,13 +33,6 @@
 */
class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorInterface {

  /**
   * The asset resolver service.
   *
   * @var \Drupal\Core\Asset\AssetResolverInterface
   */
  protected $assetResolver;

  /**
   * A config object for the system performance configuration.
   *
@@ -47,74 +40,37 @@ class HtmlResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
   */
  protected $config;

  /**
   * The CSS asset collection renderer service.
   *
   * @var \Drupal\Core\Asset\AssetCollectionRendererInterface
   */
  protected $cssCollectionRenderer;

  /**
   * The JS asset collection renderer service.
   *
   * @var \Drupal\Core\Asset\AssetCollectionRendererInterface
   */
  protected $jsCollectionRenderer;

  /**
   * The request stack.
   *
   * @var \Symfony\Component\HttpFoundation\RequestStack
   */
  protected $requestStack;

  /**
   * The renderer.
   *
   * @var \Drupal\Core\Render\RendererInterface
   */
  protected $renderer;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * Constructs a HtmlResponseAttachmentsProcessor object.
   *
   * @param \Drupal\Core\Asset\AssetResolverInterface $asset_resolver
   * @param \Drupal\Core\Asset\AssetResolverInterface $assetResolver
   *   An asset resolver.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   A config factory for retrieving required config objects.
   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $css_collection_renderer
   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $cssCollectionRenderer
   *   The CSS asset collection renderer.
   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $js_collection_renderer
   * @param \Drupal\Core\Asset\AssetCollectionRendererInterface $jsCollectionRenderer
   *   The JS asset collection renderer.
   * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
   * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
   *   The request stack.
   * @param \Drupal\Core\Render\RendererInterface $renderer
   *   The renderer.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler service.
   * @param \Drupal\Core\Language\LanguageManagerInterface|null $languageManager
   * @param \Drupal\Core\Language\LanguageManagerInterface $languageManager
   *   The language manager.
   */
  public function __construct(AssetResolverInterface $asset_resolver, ConfigFactoryInterface $config_factory, AssetCollectionRendererInterface $css_collection_renderer, AssetCollectionRendererInterface $js_collection_renderer, RequestStack $request_stack, RendererInterface $renderer, ModuleHandlerInterface $module_handler, protected ?LanguageManagerInterface $languageManager = NULL) {
    $this->assetResolver = $asset_resolver;
  public function __construct(
    protected AssetResolverInterface $assetResolver,
    ConfigFactoryInterface $config_factory,
    protected AssetCollectionRendererInterface $cssCollectionRenderer,
    protected AssetCollectionRendererInterface $jsCollectionRenderer,
    protected RequestStack $requestStack,
    protected RendererInterface $renderer,
    protected ModuleHandlerInterface $moduleHandler,
    protected LanguageManagerInterface $languageManager,
  ) {
    $this->config = $config_factory->get('system.performance');
    $this->cssCollectionRenderer = $css_collection_renderer;
    $this->jsCollectionRenderer = $js_collection_renderer;
    $this->requestStack = $request_stack;
    $this->renderer = $renderer;
    $this->moduleHandler = $module_handler;
    if (!isset($languageManager)) {
      // phpcs:ignore Drupal.Semantics.FunctionTriggerError
      @trigger_error('Calling ' . __METHOD__ . '() without the $languageManager argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0', E_USER_DEPRECATED);
      $this->languageManager = \Drupal::languageManager();
    }
  }

  /**
Loading