Skip to content
Snippets Groups Projects

Issue #2834982: Replace non-test usages of \Drupal::service('renderer') with IoC injection

Open spokje requested to merge issue/drupal-2834982:2834982-replace-non-test-usages into 10.1.x

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
51 54 * The image factory service.
52 55 */
53 public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info, ImageFactory $image_factory = NULL) {
54 parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info);
55 $this->imageFactory = $image_factory ?: \Drupal::service('image.factory');
56 public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info, RendererInterface $renderer = NULL, ImageFactory $image_factory = NULL) {
57 if (!$renderer) {
58 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
59 $renderer = \Drupal::service('renderer');
60 }
61 parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info, $renderer);
62 if (!$image_factory) {
63 @trigger_error('Calling ' . __METHOD__ . '() without the $image_factory argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
64 $image_factory = \Drupal::service('image.factory');
65 }
66 $this->imageFactory = $image_factory;
  • Comment on lines +62 to +66

    Should we do this at all? My reasoning here is that we're getting into a lot of moving arguments around if there's a NULL-able one before one that will become required in 11.0.x.

    If we should do this, can we do this in this issue, or is this one for a separate issue, which would need to land first before we can commit this issue?

  • Please register or sign in to reply
  • spokje
    spokje @Spokje started a thread on the diff
  • 42 48 * Definition.
    43 49 * @param \Drupal\filter\FilterPluginManager $filter_manager
    44 50 * Filter plugin manager.
    51 * @param \Drupal\Core\Render\RendererInterface $renderer
    52 * The renderer service.
    45 53 */
    46 public function __construct(array $configuration, $plugin_id, $plugin_definition, FilterPluginManager $filter_manager = NULL) {
    54 public function __construct(array $configuration, $plugin_id, $plugin_definition, FilterPluginManager $filter_manager = NULL, RendererInterface $renderer = NULL) {
    47 55 parent::__construct($configuration, $plugin_id, $plugin_definition);
    48 $this->filterManager = $filter_manager ?: \Drupal::service('plugin.manager.filter');
    56 $this->filterManager = $filter_manager;
    57 if (!$filter_manager) {
    58 @trigger_error('Calling ' . __METHOD__ . '() without the $filter_manager argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
    59 $filter_manager = \Drupal::service('plugin.manager.filter');
    60 }
    61 $this->filterManager = $filter_manager;
    • Comment on lines +56 to +61

      Should we do this at all? My reasoning here is that we're getting into a lot of moving arguments around if there's a NULL-able one before one that will become required in 11.0.x.

      If we should do this, can we do this in this issue, or is this one for a separate issue, which would need to land first before we can commit this issue?

    • Please register or sign in to reply
  • spokje added 1 commit
  • 42 43 */
    43 44 protected $entityRepository;
    44 45
    46 /**
    47 * The renderer service.
    48 */
    49 protected RendererInterface $renderer;
    50
    45 51 /**
  • 51 57 * The book manager.
    52 58 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
    53 59 * The entity repository service.
    60 * @param \Drupal\Core\Render\RendererInterface $renderer
    61 * The renderer service.
    54 62 */
    55 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository) {
    63 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository, RendererInterface $renderer = NULL) {
    • Suggested change
      63 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository, RendererInterface $renderer = NULL) {
      63 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository, protected RendererInterface $renderer = NULL) {
    • Please register or sign in to reply
  • 52 58 * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
    53 59 * The entity repository service.
    60 * @param \Drupal\Core\Render\RendererInterface $renderer
    61 * The renderer service.
    54 62 */
    55 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository) {
    63 public function __construct(EntityStorageInterface $node_storage, BookManagerInterface $book_manager, EntityRepositoryInterface $entity_repository, RendererInterface $renderer = NULL) {
    56 64 $this->nodeStorage = $node_storage;
    57 65 $this->bookManager = $book_manager;
    58 66 $this->entityRepository = $entity_repository;
    67 if (!$renderer) {
    68 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
    69 $renderer = \Drupal::service('renderer');
    70 }
    71 $this->renderer = $renderer;
    59 72 }
    • Comment on lines 58 to 59
      Suggested change
      66 $this->entityRepository = $entity_repository;
      67 if (!$renderer) {
      68 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
      69 $renderer = \Drupal::service('renderer');
      70 }
      71 $this->renderer = $renderer;
      72 }
      66 $this->entityRepository = $entity_repository;
      67 if ($this->renderer === NULL) {
      68 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
      69 $this->renderer = \Drupal::service('renderer');
      70 }
      71 }
    • Please register or sign in to reply
  • 22 24 */
    23 25 protected $build;
    24 26
    27 /**
    28 * Constructs an EntityLink object.
    29 *
    30 * @param array $configuration
    31 * A configuration array containing information about the plugin instance.
    32 * @param string $plugin_id
    33 * The plugin_id for the plugin instance.
    34 * @param mixed $plugin_definition
    35 * The plugin implementation definition.
    36 * @param \Drupal\Core\Render\RendererInterface $renderer
    37 * The renderer service.
    38 */
    39 public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer = NULL) {
    • Suggested change
      39 public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer = NULL) {
      39 public function __construct(array $configuration, $plugin_id, $plugin_definition, protected RendererInterface $renderer = NULL) {
    • Please register or sign in to reply
  • 31 * A configuration array containing information about the plugin instance.
    32 * @param string $plugin_id
    33 * The plugin_id for the plugin instance.
    34 * @param mixed $plugin_definition
    35 * The plugin implementation definition.
    36 * @param \Drupal\Core\Render\RendererInterface $renderer
    37 * The renderer service.
    38 */
    39 public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer = NULL) {
    40 parent::__construct($configuration, $plugin_id, $plugin_definition);
    41 if (!$renderer) {
    42 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
    43 $renderer = \Drupal::service('renderer');
    44 }
    45 $this->renderer = $renderer;
    46 }
    • Comment on lines +40 to +46
      Suggested change
      40 parent::__construct($configuration, $plugin_id, $plugin_definition);
      41 if (!$renderer) {
      42 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
      43 $renderer = \Drupal::service('renderer');
      44 }
      45 $this->renderer = $renderer;
      46 }
      40 parent::__construct($configuration, $plugin_id, $plugin_definition);
      41 if ($this->renderer === NULL) {
      42 @trigger_error('Calling ' . __METHOD__ . '() without the $renderer argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/2876656', E_USER_DEPRECATED);
      43 $this->renderer = \Drupal::service('renderer');
      44 }
      45 }
    • Please register or sign in to reply
  • 30 32 */
    31 33 public string $uid;
    32 34
    35 /**
    36 * Constructs an StatisticsLastCommentName object.
    37 *
    38 * @param array $configuration
    39 * A configuration array containing information about the plugin instance.
    40 * @param string $plugin_id
    41 * The plugin_id for the plugin instance.
    42 * @param mixed $plugin_definition
    43 * The plugin implementation definition.
    44 * @param \Drupal\Core\Render\RendererInterface $renderer
    45 * The renderer service.
    46 */
    47 public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer = NULL) {
    • Suggested change
      47 public function __construct(array $configuration, $plugin_id, $plugin_definition, RendererInterface $renderer = NULL) {
      47 public function __construct(array $configuration, $plugin_id, $plugin_definition, protected RendererInterface $renderer = NULL) {
    • Please register or sign in to reply
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading