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

ISTWCMS-5754: updating to use DI to menu report

parent 4b313925
No related branches found
No related tags found
1 merge request!270Feature/istwcms 5754 ebremner csv menu report
......@@ -2,10 +2,12 @@
namespace Drupal\uw_cfg_common\Controller;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url;
use Drupal\path_alias\AliasManager;
use Drupal\transliterate_filenames\SanitizeName;
use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
......@@ -29,6 +31,21 @@ class UwDownloadCsvController extends ControllerBase {
*/
protected $pathAlias;
/**
* Sanitize name.
*
* @var Drupal\transliterate_filenames\SanitizeName
*/
protected $sanitizeName;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/**
* The database connection.
*
......@@ -43,16 +60,25 @@ class UwDownloadCsvController extends ControllerBase {
* The entity type manager.
* @param Drupal\path_alias\AliasManager $pathAlias
* The path alias.
* @param Drupal\transliterate_filenames\SanitizeName $sanitizeName
* The sanitize name.
* @param Drupal\Core\Config\ConfigFactory $configFactory
* The config factory.
* @param \Drupal\Core\Database\Connection $database
* The database.
*/
public function __construct(
EntityTypeManagerInterface $entityTypeManager,
AliasManager $pathAlias,
SanitizeName $sanitizeName,
ConfigFactory $configFactory,
Connection $database
) {
$this->entityTypeManager = $entityTypeManager;
$this->pathAlias = $pathAlias;
$this->sanitizeName = $sanitizeName;
$this->configFactory = $configFactory;
$this->database = $database;
}
......@@ -63,6 +89,8 @@ class UwDownloadCsvController extends ControllerBase {
return new static(
$container->get('entity_type.manager'),
$container->get('path_alias.manager'),
$container->get('transliterate_filenames.sanitize_name'),
$container->get('config.factory'),
$container->get('database')
);
}
......@@ -107,7 +135,7 @@ class UwDownloadCsvController extends ControllerBase {
// Pull out the info about the node.
$data = [
'nid' => $node->id(),
'title' => '"' . $node->getTitle() . '"',
'title' => '"' . str_replace('"', '""', $node->getTitle()) . '"',
'type' => $node->type->entity->label(),
'path' => $this->pathAlias->getAliasByPath('/node/' . $node->id()),
'published' => $node->status->value,
......@@ -125,9 +153,16 @@ class UwDownloadCsvController extends ControllerBase {
// Create the response for the CSV page.
$response = new Response($content);
// Determine the filename for the CSV.
$sitename = $this->configFactory->get('system.site')->get('name');
$filename = $sitename . '_content_report.csv';
// Make sure we are using a safe filename.
$filename = $this->sanitizeName->sanitizeFilename($filename);
// Set the headers for the CSV.
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="content_report.csv"');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
}
return $response;
......@@ -312,9 +347,16 @@ class UwDownloadCsvController extends ControllerBase {
// Create the response for the CSV page.
$response = new Response($content);
// Determine the filename for the CSV.
$sitename = $this->configFactory->get('system.site')->get('name');
$filename = $sitename . '_menu_report.csv';
// Make sure we are using a safe filename.
$filename = $this->sanitizeName->sanitizeFilename($filename);
// Set the headers for the CSV.
$response->headers->set('Content-Type', 'text/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="menu_report.csv"');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
return $response;
}
......
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