NodeAuthor.php in Display Suite 8.2
File
src/Plugin/DsField/Node/NodeAuthor.php
View source
<?php
namespace Drupal\ds\Plugin\DsField\Node;
use Drupal\ds\Plugin\DsField\DsFieldBase;
class NodeAuthor extends DsFieldBase {
public function build() {
$node = $this
->entity();
$user = $node
->getOwner();
if (empty($user->name)) {
return array(
'#plain_text' => \Drupal::config('user.settings')
->get('anonymous'),
);
}
$field = $this
->getFieldConfiguration();
if ($field['formatter'] == 'author') {
return array(
'#markup' => $user
->getUsername(),
'#cache' => array(
'tags' => $user
->getCacheTags(),
),
);
}
if ($field['formatter'] == 'author_linked') {
return array(
'#theme' => 'username',
'#account' => $user,
'#cache' => array(
'tags' => $user
->getCacheTags(),
),
);
}
return array();
}
public function formatters() {
$formatters = array(
'author' => $this
->t('Author'),
'author_linked' => $this
->t('Author linked to profile'),
);
return $formatters;
}
}