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
15946fe9
Commit
15946fe9
authored
3 years ago
by
Eric Bremner
Committed by
Kevin Paxman
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4704: adding functions to get header and footer data for node/content types
parent
bd857ba9
No related branches found
No related tags found
2 merge requests
!111
Tag 1.0.1
,
!107
Feature/istwcms 4704 ebremner layout header footer
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Service/UWService.php
+99
-0
99 additions, 0 deletions
src/Service/UWService.php
src/Service/UWServiceInterface.php
+35
-0
35 additions, 0 deletions
src/Service/UWServiceInterface.php
with
134 additions
and
0 deletions
src/Service/UWService.php
+
99
−
0
View file @
15946fe9
...
@@ -5,9 +5,12 @@ namespace Drupal\uw_cfg_common\Service;
...
@@ -5,9 +5,12 @@ namespace Drupal\uw_cfg_common\Service;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Url
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\NodeInterface
;
use
Drupal\node\NodeInterface
;
use
Drupal\simplify_menu
\MenuItems
;
use
Drupal\simplify_menu
\MenuItems
;
use
Drupal\path_alias
\AliasManager
;
use
Drupal\path_alias
\AliasManager
;
use
Drupal\taxonomy\Entity\Term
;
/**
/**
* Class UWService.
* Class UWService.
...
@@ -473,4 +476,100 @@ class UWService implements UWServiceInterface {
...
@@ -473,4 +476,100 @@ class UWService implements UWServiceInterface {
}
}
}
}
/**
* {@inheritDoc}
*/
public
function
uwGetHeaderData
(
Node
$node
):
array
{
// Get the header data, depending on the content type.
switch
(
$node
->
getType
())
{
case
'uw_ct_blog'
;
// Get the author field from the node, if there is
// no author specified the value will be NULL.
$author
=
$node
->
field_author
->
value
;
// If there is no author in the field, get the last
// person to revise teh blog post.
if
(
!
$author
)
{
// Set the author to the person who made blog.
$author
=
$node
->
getOwner
()
->
getDisplayName
();
}
// Set the header data.
$header_data
=
[
'date'
=>
date
(
'l, F j, Y'
,
strtotime
(
$node
->
field_uw_blog_date
->
value
)),
'author'
=>
$author
,
'audiences'
=>
$this
->
uwGetTerms
(
$node
->
field_uw_audience
->
getValue
()),
'title'
=>
$node
->
getTitle
(),
];
break
;
}
// Return the header data.
return
$header_data
;
}
/**
* {@inheritDoc}
*/
public
function
uwGetFooterData
(
Node
$node
):
array
{
// Array to hold the footer data, need to set to
// null in case there are no footer data to be
// returned.
$footer_data
=
[];
// Get the footer data, depending on the content type.
switch
(
$node
->
getType
())
{
case
'uw_ct_blog'
;
$footer_data
=
[
'tags'
=>
$this
->
uwGetTerms
(
$node
->
get
(
'field_uw_blog_tags'
)
->
getValue
(),
'tags'
),
];
break
;
}
// Return the header data.
return
$footer_data
;
}
/**
* {@inheritDoc}
*/
public
function
uwGetTerms
(
array
$tids
,
string
$type
=
NULL
):
array
{
// Array to hold the terms, need to set to
// null in case there are no terms to be
// returned.
$terms
=
[];
// Step through each of the tids and get the term name.
foreach
(
$tids
as
$tid
)
{
// Load the term.
$term
=
Term
::
load
(
$tid
[
'target_id'
]);
// If this is a tags term type, we have to include
// url and title. If not just the tag name.
if
(
$type
==
'tags'
)
{
$terms
[]
=
[
'title'
=>
$term
->
getName
(),
'url'
=>
Url
::
fromRoute
(
'entity.taxonomy_term.canonical'
,
[
'taxonomy_term'
=>
$tid
[
'target_id'
]]
)
->
toString
(),
];
}
else
{
$terms
[]
=
$term
->
getName
();
}
}
// Return an array of term names.
return
$terms
;
}
}
}
This diff is collapsed.
Click to expand it.
src/Service/UWServiceInterface.php
+
35
−
0
View file @
15946fe9
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
Drupal\uw_cfg_common\Service
;
namespace
Drupal\uw_cfg_common\Service
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\Core\Entity\EntityInterface
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\NodeInterface
;
use
Drupal\node\NodeInterface
;
/**
/**
...
@@ -167,4 +168,38 @@ interface UWServiceInterface {
...
@@ -167,4 +168,38 @@ interface UWServiceInterface {
*/
*/
public
function
uwMonthNameShort
(
int
$month
=
NULL
);
public
function
uwMonthNameShort
(
int
$month
=
NULL
);
/**
* A function to get the header data for a node/content type.
*
* @param Node $node
* The node object.
*
* @return array
* An array containing the header data for a node/content type.
*/
public
function
uwGetHeaderData
(
Node
$node
):
array
;
/**
* A function to get the footer data for a node/content type.
*
* @param Node $node
* The node object.
*
* @return array
* An array containing the footer data for a node/content type.
*/
public
function
uwGetFooterData
(
Node
$node
):
array
;
/**
* A function get the taxonomy terms.
*
* @param array $tids
* An array of term ids (tids).
* @param string $type
* The type of terms to get, if none provided just term name returned.
*
* @return array
* An array of terms with name and link.
*/
public
function
uwGetTerms
(
array
$tids
,
string
$type
=
NULL
):
array
;
}
}
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