public function NodeSubmittedBy::build in Display Suite 8.2
Same name and namespace in other branches
- 8.4 src/Plugin/DsField/Node/NodeSubmittedBy.php \Drupal\ds\Plugin\DsField\Node\NodeSubmittedBy::build()
- 8.3 src/Plugin/DsField/Node/NodeSubmittedBy.php \Drupal\ds\Plugin\DsField\Node\NodeSubmittedBy::build()
Renders a field.
Overrides Date::build
File
- src/
Plugin/ DsField/ Node/ NodeSubmittedBy.php, line 57
Class
- NodeSubmittedBy
- Plugin that renders the submitted by field.
Namespace
Drupal\ds\Plugin\DsField\NodeCode
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 = array(
'#theme' => 'username',
'#account' => $account,
);
return array(
'#markup' => $this
->t('Submitted by <a href=":user_link">@user</a> on @date.', array(
'@user' => $this->renderer
->render($user_name),
'@date' => $this->dateFormatter
->format($this
->entity()->created->value, $date_format),
':user_link' => Url::fromUri('entity:user/' . $account
->id())
->toString(),
)),
'#cache' => array(
'tags' => $account
->getCacheTags(),
),
);
}