/** * Get the entity owner if applicable. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * * @return \Drupal\user\UserInterface|null */ protected function getEntityOwner(ContentEntityInterface $entity) { if ($entity instanceof EntityOwnerInterface) { return $entity->getOwner(); } return NULL; }
protected function getRevisionDescription(ContentEntityInterface $revision, $is_current = FALSE) { /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface $revision */ if ($revision instanceof EntityOwnerInterface) { $username = ['#theme' => 'username', '#account' => $revision->getOwner()]; } else { $username = ''; } if ($revision instanceof ExpandedEntityRevisionInterface) { // Use revision link to link to revisions that are not active. $date = $this->dateFormatter()->format($revision->getRevisionCreationTime(), 'short'); if (!$is_current) { $link = $this->l($date, $revision->urlInfo('revision')); } else { $link = $revision->link($date); } } else { $link = $revision->link($revision->label(), 'revision'); } $markup = ''; if ($revision instanceof EntityRevisionLogInterface) { $markup = $revision->getRevisionLog(); } if ($username) { $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}'; } else { $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}'; } $column = ['data' => ['#type' => 'inline_template', '#template' => $template, '#context' => ['date' => $link, 'username' => $this->renderer()->renderPlain($username), 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()]]]]; return $column; }