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 @@ ...@@ -2,10 +2,12 @@
namespace Drupal\uw_cfg_common\Controller; namespace Drupal\uw_cfg_common\Controller;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Controller\ControllerBase; use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\path_alias\AliasManager; use Drupal\path_alias\AliasManager;
use Drupal\transliterate_filenames\SanitizeName;
use Drupal\Core\Database\Connection; use Drupal\Core\Database\Connection;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
...@@ -29,6 +31,21 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -29,6 +31,21 @@ class UwDownloadCsvController extends ControllerBase {
*/ */
protected $pathAlias; protected $pathAlias;
/**
* Sanitize name.
*
* @var Drupal\transliterate_filenames\SanitizeName
*/
protected $sanitizeName;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactory
*/
protected $configFactory;
/** /**
* The database connection. * The database connection.
* *
...@@ -43,16 +60,25 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -43,16 +60,25 @@ 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.
* @param Drupal\Core\Config\ConfigFactory $configFactory
* The config factory.
* @param \Drupal\Core\Database\Connection $database * @param \Drupal\Core\Database\Connection $database
* The database. * The database.
*/ */
public function __construct( public function __construct(
EntityTypeManagerInterface $entityTypeManager, EntityTypeManagerInterface $entityTypeManager,
AliasManager $pathAlias, AliasManager $pathAlias,
SanitizeName $sanitizeName,
ConfigFactory $configFactory,
Connection $database Connection $database
) { ) {
$this->entityTypeManager = $entityTypeManager; $this->entityTypeManager = $entityTypeManager;
$this->pathAlias = $pathAlias; $this->pathAlias = $pathAlias;
$this->sanitizeName = $sanitizeName;
$this->configFactory = $configFactory;
$this->database = $database; $this->database = $database;
} }
...@@ -63,6 +89,8 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -63,6 +89,8 @@ class UwDownloadCsvController extends ControllerBase {
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'),
$container->get('config.factory'),
$container->get('database') $container->get('database')
); );
} }
...@@ -107,7 +135,7 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -107,7 +135,7 @@ class UwDownloadCsvController extends ControllerBase {
// Pull out the info about the node. // Pull out the info about the node.
$data = [ $data = [
'nid' => $node->id(), 'nid' => $node->id(),
'title' => '"' . $node->getTitle() . '"', 'title' => '"' . str_replace('"', '""', $node->getTitle()) . '"',
'type' => $node->type->entity->label(), 'type' => $node->type->entity->label(),
'path' => $this->pathAlias->getAliasByPath('/node/' . $node->id()), 'path' => $this->pathAlias->getAliasByPath('/node/' . $node->id()),
'published' => $node->status->value, 'published' => $node->status->value,
...@@ -125,9 +153,16 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -125,9 +153,16 @@ class UwDownloadCsvController extends ControllerBase {
// Create the response for the CSV page. // Create the response for the CSV page.
$response = new Response($content); $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. // Set the headers for the CSV.
$response->headers->set('Content-Type', 'text/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; return $response;
...@@ -312,9 +347,16 @@ class UwDownloadCsvController extends ControllerBase { ...@@ -312,9 +347,16 @@ class UwDownloadCsvController extends ControllerBase {
// Create the response for the CSV page. // Create the response for the CSV page.
$response = new Response($content); $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. // Set the headers for the CSV.
$response->headers->set('Content-Type', 'text/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; 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