diff --git a/src/Service/UWService.php b/src/Service/UWService.php index d107c1edb58b6cbbd08a0643e24994d92b0b0326..9e2852550a17f8a72c20856fa4d75e4217c2c4cb 100644 --- a/src/Service/UWService.php +++ b/src/Service/UWService.php @@ -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; diff --git a/src/Service/UWServiceInterface.php b/src/Service/UWServiceInterface.php index 844ee6cc93b22a0eba20f1052c62d9af0c7edd57..c4818aa19e7a93524f8dcf99eb53fa9658026503 100644 --- a/src/Service/UWServiceInterface.php +++ b/src/Service/UWServiceInterface.php @@ -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.