CommentUser.php in Display Suite 8.4
File
src/Plugin/DsField/Comment/CommentUser.php
View source
<?php
namespace Drupal\ds\Plugin\DsField\Comment;
use Drupal\Core\Entity\EntityDisplayRepositoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\ds\Plugin\DsField\Entity;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CommentUser extends Entity {
protected $entityTypeManager;
public function __construct($configuration, $plugin_id, $plugin_definition, EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_display_repository);
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_display.repository'), $container
->get('entity_type.manager'));
}
public function build() {
$view_mode = $this
->getEntityViewMode();
$comment = $this
->entity();
$uid = $comment
->getOwnerId();
$user = $this->entityTypeManager
->getStorage('user')
->load($uid);
$build = [];
if ($user) {
$build = $this->entityTypeManager
->getViewBuilder('user')
->view($user, $view_mode);
}
return $build;
}
public function linkedEntity() {
return 'user';
}
}