You are here

public function NodeSubmittedBy::build in Display Suite 8.4

Same name and namespace in other branches
  1. 8.2 src/Plugin/DsField/Node/NodeSubmittedBy.php \Drupal\ds\Plugin\DsField\Node\NodeSubmittedBy::build()
  2. 8.3 src/Plugin/DsField/Node/NodeSubmittedBy.php \Drupal\ds\Plugin\DsField\Node\NodeSubmittedBy::build()

Renders a field.

Return value

array A renderable array representing the content of the field.

Overrides Date::build

File

src/Plugin/DsField/Node/NodeSubmittedBy.php, line 58

Class

NodeSubmittedBy
Plugin that renders the submitted by field.

Namespace

Drupal\ds\Plugin\DsField\Node

Code

public function build() {
  $field = $this
    ->getFieldConfiguration();

  /* @var $node \Drupal\node\NodeInterface */
  $node = $this
    ->entity();

  /* @var $account \Drupal\user\UserInterface */
  $account = $node
    ->getOwner();
  $date_format = str_replace('ds_post_date_', '', $field['formatter']);
  $user_name = [
    '#theme' => 'username',
    '#account' => $account,
  ];
  return [
    '#markup' => $this
      ->t('Submitted by @user on @date.', [
      '@user' => $this->renderer
        ->render($user_name),
      '@date' => $this->dateFormatter
        ->format($this
        ->entity()->created->value, $date_format),
    ]),
    '#cache' => [
      'tags' => $account
        ->getCacheTags(),
    ],
  ];
}