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
973222bf
Commit
973222bf
authored
3 years ago
by
Eric Bremner
Committed by
Eric Bremner
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-4619: refactoring get node content to work with all view modes
parent
0452c547
No related branches found
No related tags found
2 merge requests
!111
Tag 1.0.1
,
!110
Feature/istwcms 4619 ebremner variables for listing page
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Service/UWService.php
+40
-34
40 additions, 34 deletions
src/Service/UWService.php
src/Service/UWServiceInterface.php
+13
-11
13 additions, 11 deletions
src/Service/UWServiceInterface.php
with
53 additions
and
45 deletions
src/Service/UWService.php
+
40
−
34
View file @
973222bf
...
...
@@ -105,7 +105,7 @@ class UWService implements UWServiceInterface {
/**
* {@inheritDoc}
*/
public
function
getTeaser
Content
(
Node
$node
,
string
$
teaser
_type
,
string
$
teaser_
content
=
'all'
):
array
{
public
function
uwGetNode
Content
(
Node
$node
,
string
$
content
_type
,
string
$
view_mode
,
string
$
content
=
'all'
):
array
{
// Flags for getting teaser content.
$get_header
=
FALSE
;
...
...
@@ -114,24 +114,27 @@ class UWService implements UWServiceInterface {
$get_content
=
FALSE
;
// Setup flags based on teaser content argument.
if
(
$
teaser_
content
==
'all'
)
{
if
(
$content
==
'all'
)
{
$get_header
=
TRUE
;
$get_footer
=
TRUE
;
$get_image
=
TRUE
;
$get_content
=
TRUE
;
if
(
$view_mode
==
'teaser'
)
{
$get_image
=
TRUE
;
}
}
else
{
if
(
$
teaser_
content
==
'header'
)
{
if
(
$content
==
'header'
)
{
$get_header
=
TRUE
;
}
if
(
$
teaser_
content
==
'footer'
)
{
if
(
$content
==
'footer'
)
{
$get_footer
=
TRUE
;
}
}
// Setup the teaser data array, based on flags.
switch
(
$
teaser
_type
)
{
switch
(
$
content
_type
)
{
case
'blog'
:
...
...
@@ -141,7 +144,7 @@ class UWService implements UWServiceInterface {
'field_uw_audience'
,
];
$
teaser
_data
=
[
$
content
_data
=
[
'title'
=>
$get_header
?
TRUE
:
NULL
,
'url'
=>
TRUE
,
'date'
=>
$get_header
?
'field_uw_blog_date'
:
NULL
,
...
...
@@ -161,7 +164,7 @@ class UWService implements UWServiceInterface {
'field_uw_event_type'
,
];
$
teaser
_data
=
[
$
content
_data
=
[
'title'
=>
$get_header
?
TRUE
:
NULL
,
'url'
=>
TRUE
,
'date'
=>
$get_header
?
'field_uw_event_date'
:
NULL
,
...
...
@@ -179,7 +182,7 @@ class UWService implements UWServiceInterface {
'field_uw_audience'
,
];
$
teaser
_data
=
[
$
content
_data
=
[
'title'
=>
$get_header
?
TRUE
:
NULL
,
'url'
=>
TRUE
,
'date'
=>
$get_header
?
'field_uw_news_date'
:
NULL
,
...
...
@@ -190,22 +193,22 @@ class UWService implements UWServiceInterface {
break
;
}
return
$this
->
getTeaser
Data
(
$node
,
$
teaser
_type
,
$
teaser
_data
);
return
$this
->
uwGetNode
Data
(
$node
,
$
content
_type
,
$
view_mode
,
$content
_data
);
}
/**
* {@inheritDoc}
*/
public
function
getTeaser
Data
(
Node
$node
,
string
$
teaser_type
,
array
$teaser
_data
):
array
{
public
function
uwGetNode
Data
(
Node
$node
,
string
$
content_type
,
string
$view_mode
,
array
$content
_data
):
array
{
// Array to store the teaser data, need blank
// array in case there is no data to return.
$
teaser
=
[];
$
node_data
=
[];
// Step through each of the teaser data, and if
// we are to get the data then set the variable
// inside the teaser array.
foreach
(
$
teaser
_data
as
$index
=>
$data
)
{
foreach
(
$
content
_data
as
$index
=>
$data
)
{
// If there is data to get, then get it.
if
(
$data
)
{
...
...
@@ -216,24 +219,25 @@ class UWService implements UWServiceInterface {
switch
(
$index
)
{
case
'title'
:
$
teaser
[
'title'
]
=
$node
->
getTitle
();
$
node_data
[
'title'
]
=
$node
->
getTitle
();
break
;
case
'author'
:
$
teaser
[
'author'
]
=
$this
->
uwGetAuthor
(
$node
);
$
node_data
[
'author'
]
=
$this
->
uwGetAuthor
(
$node
);
break
;
case
'date'
:
if
(
$
teaser_typ
e
!
==
'
event
'
)
{
$teaser
[
'date'
]
=
date
(
'l, F j, Y'
,
strtotime
(
$node
->
$data
->
value
));
}
else
{
if
(
$
view_mod
e
==
'
teaser
'
)
{
if
(
$content_type
!==
'events'
)
{
$node_data
[
'date'
]
=
date
(
'l, F j, Y'
,
strtotime
(
$node
->
$data
->
value
));
}
else
{
// Get all the dates.
// @todo figure out what date to display for events.
$dates
=
$node
->
$data
->
getValue
();
// Get all the dates.
// @todo figure out what date to display for events.
$dates
=
$node
->
$data
->
getValue
();
$teaser
[
'date'
]
=
date
(
'l, F j, Y'
,
$dates
[
0
][
'value'
]);
$node_data
[
'date'
]
=
date
(
'l, F j, Y'
,
$dates
[
0
][
'value'
]);
}
}
break
;
...
...
@@ -251,18 +255,20 @@ class UWService implements UWServiceInterface {
}
if
(
isset
(
$sources
[
'responsive_sources'
]))
{
$
teaser
[
'image'
][
'sources'
]
=
$sources
[
'sources'
];
$
teaser
[
'image'
][
'img_element'
]
=
$sources
[
'img_element'
][
'#uri'
];
$
teaser
[
'image'
][
'alt'
]
=
$sources
[
'alt'
];
$
node_data
[
'image'
][
'sources'
]
=
$sources
[
'sources'
];
$
node_data
[
'image'
][
'img_element'
]
=
$sources
[
'img_element'
][
'#uri'
];
$
node_data
[
'image'
][
'alt'
]
=
$sources
[
'alt'
];
}
break
;
case
'content'
:
$teaser
[
'content'
]
=
[
'#type'
=>
'processed_text'
,
'#text'
=>
$node
->
$data
->
value
,
'#format'
=>
$node
->
$data
->
format
,
];
if
(
$view_mode
==
'teaser'
)
{
$node_data
[
'content'
]
=
[
'#type'
=>
'processed_text'
,
'#text'
=>
$node
->
$data
->
value
,
'#format'
=>
$node
->
$data
->
format
,
];
}
break
;
case
'tags'
:
...
...
@@ -270,17 +276,17 @@ class UWService implements UWServiceInterface {
foreach
(
$data
as
$field
)
{
$tags
=
array_merge
(
$tags
,
$this
->
uwGetTermsFromEntityField
(
$node
->
$field
,
'tags'
));
}
$
teaser
[
'tags'
]
=
[
$tags
];
$
node_data
[
'tags'
]
=
[
$tags
];
break
;
case
'url'
:
$
teaser
[
'url'
]
=
$node
->
toUrl
()
->
toString
();
$
node_data
[
'url'
]
=
$node
->
toUrl
()
->
toString
();
break
;
}
}
}
return
$
teaser
;
return
$
node_data
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
src/Service/UWServiceInterface.php
+
13
−
11
View file @
973222bf
...
...
@@ -34,32 +34,34 @@ interface UWServiceInterface {
*
* @param \Drupal\node\NodeInterface $node
* Node entity.
* @param
array $variables_to_get
*
List of variables to return
.
* @param string $
teaser_typ
e
* T
easer type
.
* @param string $
teaser_
content
* @param
string $content_type
*
The content type (i.e. news, event, blog, etc)
.
* @param string $
view_mod
e
* T
he view mode (i.e. node, teaser, etc)
.
* @param string $content
* The type of content to get, values are all, header or footer.
*
* @return array
* Array of variables and their values.
*/
public
function
getTeaser
Content
(
Node
$node
,
string
$
teaser
_type
,
string
$
teaser_
content
=
'all'
):
array
;
public
function
uwGetNode
Content
(
Node
$node
,
string
$
content
_type
,
string
$
view_mode
,
string
$
content
=
'all'
):
array
;
/**
* Gets teaser data.
*
* @param \Drupal\node\NodeInterface $node
* Node entity.
* @param string $teaser_type
* The type of teaser (i.e. blog, events, news, etc).
* @param array $teaser_data
* @param string $content_type
* The content type (i.e. news, event, blog, etc).
* @param string $view_mode
* The view mode (i.e. node, teaser, etc).
* @param array $content_data
* An array of all the data to get for the teaser.
*
* @return array
* Array of
teaser
values.
* Array of
node
values.
*/
public
function
getTeaser
Data
(
Node
$node
,
string
$
teaser_type
,
array
$teaser
_data
):
array
;
public
function
uwGetNode
Data
(
Node
$node
,
string
$
content_type
,
string
$view_mode
,
array
$content
_data
):
array
;
/**
* A function to get or check the attached sidebar.
...
...
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