Skip to content
Snippets Groups Projects
Commit bad5c9bd authored by Eric Bremner's avatar Eric Bremner Committed by Eric Bremner
Browse files

ISTWCMS-4619: adding author name and link

parent 45b92230
No related branches found
No related tags found
2 merge requests!111Tag 1.0.1,!110Feature/istwcms 4619 ebremner variables for listing page
......@@ -645,18 +645,34 @@ class UWService implements UWServiceInterface {
/**
* {@inheritDoc}
*/
public function uwGetAuthor(Node $node): string {
public function uwGetAuthor(Node $node): array {
// Get the author field from the node, if there is
// no author specified the value will be NULL.
$author = $node->field_author->value;
$author_name = $node->field_author->value;
// If there is no author in the field, get the last
// person to revise the blog post.
if (!$author) {
// If there is no author in the field, get the owner
// of the blog post.
if (!$author_name) {
// Set the author to the person who made blog.
$author = $node->getOwner()->getDisplayName();
$author = [
'name' => $node->getOwner()->getDisplayName(),
'link' => NULL,
];
}
// If there is an author, get the author name and link.
else {
// Get the link field from the node.
$link = $node->field_uw_author_link->getValue();
// Set the author name and link (if any).
$author = [
'name' => $author_name,
'link' => empty($link) ? NULL : $link[0]['uri'],
];
}
return $author;
......
......@@ -224,10 +224,10 @@ interface UWServiceInterface {
* @param \Drupal\node\Entity\Node $node
* The node object.
*
* @return string
* An string of the author name.
* @return array
* An array of author name and link.
*/
public function uwGetAuthor(Node $node): string;
public function uwGetAuthor(Node $node): array;
/**
* Function that parses terms and returns a list.
......
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