Use dependency injection for redirect classes

Created on 19 November 2018, over 5 years ago
Updated 5 March 2024, 4 months ago

Problem/Motivation

\Drupal calls should be avoided in classes, and we should use dependency injection instead.

Currently, redirect's classes use \Drupal style calls in the following places:

  1. src/Entity/Redirect.php: return array(\Drupal::currentUser()->id());
  2. src/EventSubscriber/RedirectRequestSubscriber.php: \Drupal::logger('redirect')->warning($e->getMessage());
  3. src/Form/RedirectForm.php: foreach (\Drupal::languageManager()->getLanguages(LanguageInterface::STATE_CONFIGURABLE) as $langcode => $language) {
  4. src/Form/RedirectForm.php: $default_code = $redirect->getStatusCode() ? $redirect->getStatusCode() : \Drupal::config('redirect.settings')->get('default_status_code');
  5. src/Form/RedirectForm.php: $redirects = \Drupal::entityManager()
  6. src/Form/RedirectSettingsForm.php: '#disabled' => !\Drupal::moduleHandler()->moduleExists('path'),
  7. src/Plugin/Field/FieldWidget/RedirectSourceWidget.php: \Drupal::service('router')->match('/' . $form_state->getValue(array('redirect_source', 0, 'path')));
  8. src/Plugin/Field/FieldWidget/RedirectSourceWidget.php: $repository = \Drupal::service('redirect.repository');
  9. src/RedirectRepository.php: $base_url = \Drupal::request()->getBaseUrl();

Proposed resolution

Define constructors and create() methods to properly inject all dependencies.

Remaining tasks

  • All in one.
  • Not needed.
  • Fix the patch to deal with all of them.
  • Reviews + testing

User interface changes

None.

API changes

Defining constructors and ::create() methods for various redirect-related classes.

Data model changes

None.

๐Ÿ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

๐Ÿ‡ง๐Ÿ‡ทBrazil thalles Teรณfilo Otoni - MG

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024