From 4343b3f2798c3fdd8d0858494853d5f59c6de613 Mon Sep 17 00:00:00 2001 From: gchi25 Date: Mon, 26 Aug 2024 13:18:21 -0400 Subject: [PATCH] Revert "Revert "PXBF-1646-update-checkdata-controller: add dependency injection"" This reverts commit 22a0aad09acca2fab59e27e4f02b1e55604fab1e. --- .../src/Controller/CheckDataController.php | 70 +++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/usagov_benefit_finder/modules/usagov_benefit_finder_content/src/Controller/CheckDataController.php b/usagov_benefit_finder/modules/usagov_benefit_finder_content/src/Controller/CheckDataController.php index e97f66a65..1d29ba007 100644 --- a/usagov_benefit_finder/modules/usagov_benefit_finder_content/src/Controller/CheckDataController.php +++ b/usagov_benefit_finder/modules/usagov_benefit_finder_content/src/Controller/CheckDataController.php @@ -2,13 +2,21 @@ namespace Drupal\usagov_benefit_finder_content\Controller; +use Drupal\Core\Controller\ControllerBase; +use Drupal\Core\Database\Connection; +use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\File\FileSystemInterface; +use Drupal\Core\File\FileUrlGeneratorInterface; +use Drupal\file\FileRepositoryInterface; use Drupal\usagov_benefit_finder\Traits\BenefitFinderTrait; +use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; /** * Class CheckDataController * @package Drupal\usagov_benefit_finder_content\Controller */ -class CheckDataController { +class CheckDataController extends ControllerBase { use BenefitFinderTrait; @@ -48,11 +56,11 @@ class CheckDataController { protected $database; /** - * Retrieves the currently active request object. + * The request stack. * - * @var \Symfony\Component\HttpFoundation\Request + * @var \Symfony\Component\HttpFoundation\RequestStack */ - protected $request; + protected $requestStack; /** * The benefit finder content mode. @@ -76,15 +84,49 @@ class CheckDataController { protected $expanded; /** - * Constructs a new LifeEventController object. + * Constructs a new CheckDataController object. + * + * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager + * The entity type manager. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * The file system service. + * @param \Drupal\file\FileRepositoryInterface|null $file_repository + * The file repository. + * @param \Drupal\Core\File\FileUrlGeneratorInterface $file_url_generator + * The file URL generator. + * @param \Drupal\Core\Database\Connection $connection + * The database connection. + * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack + * The request stack. + */ + public function __construct( + EntityTypeManagerInterface $entity_type_manager, + FileSystemInterface $file_system, + FileRepositoryInterface $file_repository, + FileUrlGeneratorInterface $file_url_generator, + Connection $database, + RequestStack $request_stack + ) { + $this->entityTypeManager = $entity_type_manager; + $this->fileSystem = $file_system; + $this->fileRepository = $file_repository; + $this->fileUrlGenerator = $file_url_generator; + $this->database = $database; + $this->requestStack = $request_stack; + } + + /** + * {@inheritdoc} */ - public function __construct() { - $this->entityTypeManager = \Drupal::service('entity_type.manager'); - $this->fileSystem = \Drupal::service('file_system'); - $this->fileRepository = \Drupal::service('file.repository'); - $this->fileUrlGenerator = \Drupal::service('file_url_generator'); - $this->database = \Drupal::service('database'); - $this->request = \Drupal::request(); + public static function create(ContainerInterface $container) { + return new static( + $container->get('entity_type.manager'), + $container->get('file_system'), + $container->get('file.repository'), + $container->get('file_url_generator'), + $container->get('database'), + $container->get('request_stack'), + ); } /** @@ -95,12 +137,12 @@ public function checkData() { // Get langcode. if (empty($this->langcode)) { - $this->langcode = $this->request->get('langcode') ?? "en"; + $this->langcode = $this->requestStack->getCurrentRequest()->query->get('langcode') ?? "en"; } // Get expanded. if (empty($this->expanded)) { - $this->expanded = $this->request->get('expanded') ?? "false"; + $this->expanded = $this->requestStack->getCurrentRequest()->query->get('expanded') ?? "false"; } $help = <<