WebformSubmissionSubmittedToRenderedEntity.php in Webform Views Integration 8.5
File
src/Plugin/views/field/WebformSubmissionSubmittedToRenderedEntity.php
View source
<?php
namespace Drupal\webform_views\Plugin\views\field;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionSubmittedToRenderedEntity extends FieldPluginBase {
use WebformSubmissionSubmittedToTrait;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityTypeManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityManager = $entity_manager;
$this->languageManager = $language_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('language_manager'));
}
public function defineOptions() {
$options = parent::defineOptions();
$options['view_mode'] = [
'default' => 'default',
];
return $options;
}
public function clickSortable() {
return FALSE;
}
public function render(ResultRow $values) {
$build = [];
$source_entity = $this
->getSourceEntity($values);
if (!$source_entity) {
return $build;
}
$source_entity = $this
->getEntityTranslation($source_entity, $values);
$access = $source_entity
->access('view', NULL, TRUE);
$build['#access'] = $access;
if ($access
->isAllowed()) {
$view_builder = $this->entityManager
->getViewBuilder($this
->getEntityTypeId());
$build += $view_builder
->view($source_entity, $this->options['view_mode']);
$cache = CacheableMetadata::createFromObject($source_entity);
$cache
->applyTo($build);
}
return $build;
}
}