public function ContentHubEntityDependency::setAuthor in Acquia Content Hub 8
Sets the author for the current node entity, if $author is given.
Parameters
string|null $author: The author's UUID if given.
File
- src/
ContentHubEntityDependency.php, line 330
Class
- ContentHubEntityDependency
- Content Hub Dependency Class.
Namespace
Drupal\acquia_contenthubCode
public function setAuthor($author = NULL) {
if ($this
->getEntityType() == 'node' && Uuid::isValid($author)) {
// Set the entity's author for node entities.
if (isset($this
->getRawEntity()['attributes']['author'])) {
// Get the language.
$languages = array_keys($this->cdf['attributes']['author']['value']);
foreach ($languages as $lang) {
$this->cdf['attributes']['author']['value'][$lang] = $author;
}
}
else {
// Set the author for each language.
$lang_author = [];
foreach ($this->cdf['attributes']['langcode']['value'] as $lang) {
$lang_author[$lang] = $author;
}
$this->cdf['attributes']['author'] = [
'type' => 'reference',
'value' => $lang_author,
];
}
}
}