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
2e382921
Commit
2e382921
authored
3 years ago
by
Igor Biki
Committed by
Kevin Paxman
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4704: Adding new way to load terms from a node. Expanding uw service.
parent
25ad68fb
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
+31
-3
31 additions, 3 deletions
src/Service/UWService.php
src/Service/UWServiceInterface.php
+16
-0
16 additions, 0 deletions
src/Service/UWServiceInterface.php
with
47 additions
and
3 deletions
src/Service/UWService.php
+
31
−
3
View file @
2e382921
...
@@ -5,6 +5,7 @@ namespace Drupal\uw_cfg_common\Service;
...
@@ -5,6 +5,7 @@ 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\Field\EntityReferenceFieldItemListInterface
;
use
Drupal\Core\Url
;
use
Drupal\Core\Url
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\NodeInterface
;
use
Drupal\node\NodeInterface
;
...
@@ -506,7 +507,7 @@ class UWService implements UWServiceInterface {
...
@@ -506,7 +507,7 @@ class UWService implements UWServiceInterface {
$header_data
=
[
$header_data
=
[
'date'
=>
date
(
'l, F j, Y'
,
strtotime
(
$node
->
field_uw_blog_date
->
value
)),
'date'
=>
date
(
'l, F j, Y'
,
strtotime
(
$node
->
field_uw_blog_date
->
value
)),
'author'
=>
$author
,
'author'
=>
$author
,
'audiences'
=>
$this
->
uwGetTerms
(
$node
->
field_uw_audience
->
getValue
(
)),
'audiences'
=>
$this
->
uwGetTerms
FromEntityField
(
$node
->
get
(
'
field_uw_audience
'
)),
'title'
=>
$node
->
getTitle
(),
'title'
=>
$node
->
getTitle
(),
];
];
break
;
break
;
...
@@ -531,8 +532,7 @@ class UWService implements UWServiceInterface {
...
@@ -531,8 +532,7 @@ class UWService implements UWServiceInterface {
case
'uw_ct_blog'
;
case
'uw_ct_blog'
;
$footer_data
=
[
$footer_data
=
[
'tags'
=>
[
'tags'
=>
[
$this
->
uwGetTerms
(
$node
->
get
(
'field_uw_blog_tags'
)
->
getValue
(),
$this
->
uwGetTermsFromEntityField
(
$node
->
get
(
'field_uw_blog_tags'
),
'tags'
),
'tags'
),
],
],
];
];
break
;
break
;
...
@@ -579,4 +579,32 @@ class UWService implements UWServiceInterface {
...
@@ -579,4 +579,32 @@ class UWService implements UWServiceInterface {
return
$terms
;
return
$terms
;
}
}
/**
* {@inheritDoc}
*/
public
function
uwGetTermsFromEntityField
(
EntityReferenceFieldItemListInterface
$values
,
string
$type
=
NULL
):
array
{
$terms
=
[];
// List of referenced taxonomy terms.
foreach
(
$values
as
$term_ref
)
{
/** @var \Drupal\taxonomy\Entity\Term $term_entity */
$term_entity
=
$term_ref
->
entity
;
if
(
$term_entity
)
{
if
(
$type
===
'tags'
)
{
$terms
[]
=
[
'title'
=>
$term_entity
->
getName
(),
// By default function toUrl on entity uses canonical url.
'url'
=>
$term_entity
->
toUrl
()
->
toString
(),
];
}
else
{
$terms
[]
=
$term_entity
->
getName
();
}
}
}
return
$terms
;
}
}
}
This diff is collapsed.
Click to expand it.
src/Service/UWServiceInterface.php
+
16
−
0
View file @
2e382921
...
@@ -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\Core\Field\EntityReferenceFieldItemListInterface
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\Entity\Node
;
use
Drupal\node\NodeInterface
;
use
Drupal\node\NodeInterface
;
...
@@ -203,4 +204,19 @@ interface UWServiceInterface {
...
@@ -203,4 +204,19 @@ interface UWServiceInterface {
*/
*/
public
function
uwGetTerms
(
array
$tids
,
string
$type
=
NULL
):
array
;
public
function
uwGetTerms
(
array
$tids
,
string
$type
=
NULL
):
array
;
/**
* Function that parses terms and returns a list.
*
* @param \Drupal\Core\Field\EntityReferenceFieldItemListInterface $values
* List of values for the provided field.
* @param string|null $type
* The type of terms to get, if none provided just term name returned.
*
* @return array
* List of terms with name and link.
*
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
public
function
uwGetTermsFromEntityField
(
EntityReferenceFieldItemListInterface
$values
,
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