Skip to content
Snippets Groups Projects
Commit 8f850956 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5753: adding DI for uw content report

parent c5193bee
No related branches found
No related tags found
1 merge request!269Feature/istwcms 5753 ebremner csv content report
...@@ -5,6 +5,7 @@ namespace Drupal\uw_cfg_common\Controller; ...@@ -5,6 +5,7 @@ namespace Drupal\uw_cfg_common\Controller;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\path_alias\AliasManager; use Drupal\path_alias\AliasManager;
use Drupal\transliterate_filenames\SanitizeName;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
...@@ -27,6 +28,13 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -27,6 +28,13 @@ class UwDownloadCsvController extends ControllerBase {
*/ */
protected $pathAlias; protected $pathAlias;
/**
* Sanitize name.
*
* @var Drupal\transliterate_filenames\SanitizeName
*/
protected $sanitizeName;
/** /**
* CSV Report constructor. * CSV Report constructor.
* *
...@@ -34,13 +42,18 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -34,13 +42,18 @@ class UwDownloadCsvController extends ControllerBase {
* The entity type manager. * The entity type manager.
* @param Drupal\path_alias\AliasManager $pathAlias * @param Drupal\path_alias\AliasManager $pathAlias
* The path alias. * The path alias.
* @param Drupal\transliterate_filenames\SanitizeName $sanitizeName
* The sanitize name.
*/ */
public function __construct( public function __construct(
EntityTypeManagerInterface $entityTypeManager, EntityTypeManagerInterface $entityTypeManager,
AliasManager $pathAlias AliasManager $pathAlias,
SanitizeName $sanitizeName
) { ) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->pathAlias = $pathAlias; $this->pathAlias = $pathAlias;
$this->sanitizeName = $sanitizeName;
} }
/** /**
...@@ -49,7 +62,8 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -49,7 +62,8 @@ class UwDownloadCsvController extends ControllerBase {
public static function create(ContainerInterface $container) { public static function create(ContainerInterface $container) {
return new static( return new static(
$container->get('entity_type.manager'), $container->get('entity_type.manager'),
$container->get('path_alias.manager') $container->get('path_alias.manager'),
$container->get('transliterate_filenames.sanitize_name')
); );
} }
...@@ -114,8 +128,9 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -114,8 +128,9 @@ class UwDownloadCsvController extends ControllerBase {
// Determine the filename for the CSV. // Determine the filename for the CSV.
$sitename = \Drupal::config('system.site')->get('name'); $sitename = \Drupal::config('system.site')->get('name');
$filename = $sitename . '_content_report.csv'; $filename = $sitename . '_content_report.csv';
// Make sure we are using a safe filename. // Make sure we are using a safe filename.
$filename = \Drupal::service('transliterate_filenames.sanitize_name')->sanitizeFilename($filename); $filename = $this->sanitizeName->sanitizeFilename($filename);
// Set the headers for the CSV. // Set the headers for the CSV.
$response->headers->set('Content-Type', 'text/csv'); $response->headers->set('Content-Type', 'text/csv');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment