Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
4cfd10fd
Commit
4cfd10fd
authored
2 years ago
by
Eric Bremner
Committed by
Kevin Paxman
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5753: adding CSV content report
parent
d218ced8
No related branches found
Branches containing commit
No related tags found
1 merge request
!269
Feature/istwcms 5753 ebremner csv content report
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Controller/UwDownloadCsvController.php
+121
-0
121 additions, 0 deletions
src/Controller/UwDownloadCsvController.php
uw_cfg_common.routing.yml
+8
-0
8 additions, 0 deletions
uw_cfg_common.routing.yml
with
129 additions
and
0 deletions
src/Controller/UwDownloadCsvController.php
0 → 100644
+
121
−
0
View file @
4cfd10fd
<?php
namespace
Drupal\uw_cfg_common\Controller
;
use
Drupal\Core\Controller\ControllerBase
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\path_alias
\AliasManager
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\Response
;
/**
* Provides CSV files for specific UW sites.
*/
class
UwDownloadCsvController
extends
ControllerBase
{
/**
* Entity type manager from the core.
*
* @var Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* @var \Drupal\path_alias\AliasManager
* The path alias.
*/
protected
$pathAlias
;
/**
* CSV Report constructor.
*
* @param Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param Drupal\path_alias\AliasManager $pathAlias
* The path alias.
*/
public
function
__construct
(
EntityTypeManagerInterface
$entityTypeManager
,
AliasManager
$pathAlias
)
{
$this
->
entityTypeManager
=
$entityTypeManager
;
$this
->
pathAlias
=
$pathAlias
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'path_alias.manager'
)
);
}
/**
* Provides a CSV file for content on a site.
*
* @return Response
* The page response.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public
function
uwContentReport
()
{
// Get all the nodes.
$nodes
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
loadMultiple
();
// Just in case there are no nodes, there should always
// be a home page though, this is just to ensure no errors.
$response
=
NULL
;
if
(
$nodes
)
{
// The header of the CSV.
$data
=
[
$this
->
t
(
'Node ID'
),
$this
->
t
(
'Title'
),
$this
->
t
(
'Content type'
),
$this
->
t
(
'Path'
),
$this
->
t
(
'Published'
),
$this
->
t
(
'Created'
),
$this
->
t
(
'Last updated'
),
];
// Put header for CSV into format to be used in CSV.
$rows
[]
=
implode
(
','
,
$data
);
// Step through each of the nodes and get the info.
foreach
(
$nodes
as
$node
)
{
// Pull out the info about the node.
$data
=
[
'nid'
=>
$node
->
id
(),
'title'
=>
'"'
.
$node
->
getTitle
()
.
'"'
,
'type'
=>
$node
->
type
->
entity
->
label
(),
'path'
=>
$this
->
pathAlias
->
getAliasByPath
(
'/node/'
.
$node
->
id
()),
'published'
=>
$node
->
status
->
value
,
'created'
=>
date
(
'Y-d-m G:i'
,
$node
->
getCreatedTime
()),
'updated'
=>
date
(
'Y-d-m G:i'
,
$node
->
getChangedTime
()),
];
// Store the node info for use later in the CSV.
$rows
[]
=
implode
(
','
,
$data
);
}
// Put the info into a large CSV format.
$content
=
implode
(
"
\n
"
,
$rows
);
// Create the response for the CSV page.
$response
=
new
Response
(
$content
);
// Set the headers for the CSV.
$response
->
headers
->
set
(
'Content-Type'
,
'text/csv'
);
$response
->
headers
->
set
(
'Content-Disposition'
,
'attachment; filename="content_report.csv"'
);
}
return
$response
;
}
}
This diff is collapsed.
Click to expand it.
uw_cfg_common.routing.yml
+
8
−
0
View file @
4cfd10fd
...
@@ -34,3 +34,11 @@ uw_cfg_common.content_type_usage_page:
...
@@ -34,3 +34,11 @@ uw_cfg_common.content_type_usage_page:
_title
:
'
Content
type
Use'
_title
:
'
Content
type
Use'
requirements
:
requirements
:
_permission
:
'
access
content'
_permission
:
'
access
content'
uw_cfg_common.uw_content_report_csv
:
path
:
'
/admin/reports/uw_content_report_csv'
defaults
:
_title
:
'
Download
Customers'
_controller
:
\Drupal\uw_cfg_common\Controller\UwDownloadCsvController::uwContentReport
requirements
:
_permission
:
'
access
content'
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment