LogViewBuilder.php in Commerce Core 8.2
File
modules/log/src/LogViewBuilder.php
View source
<?php
namespace Drupal\commerce_log;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityViewBuilder;
class LogViewBuilder extends EntityViewBuilder {
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
$build_list = [
'#sorted' => TRUE,
];
$weight = 0;
foreach ($entities as $key => $entity) {
$build_list[$key] = [
'#type' => 'inline_template',
'#template' => $entity
->getTemplate()
->getTemplate(),
'#context' => $entity
->getParams(),
'#cache' => [
'tags' => Cache::mergeTags($this
->getCacheTags(), $entity
->getCacheTags()),
'contexts' => $entity
->getCacheContexts(),
'max-age' => $entity
->getCacheMaxAge(),
],
];
$source_type = str_replace('commerce_', '', $entity
->getSourceEntityTypeId());
$build_list[$key]['#context'][$source_type] = $entity
->getSourceEntity();
$entityType = $this->entityTypeId;
$this
->moduleHandler()
->alter([
$entityType . '_build',
'entity_build',
], $build_list[$key], $entity, $view_mode);
$build_list[$key]['#weight'] = $weight++;
}
return $build_list;
}
public function view(EntityInterface $entity, $view_mode = 'full', $langcode = NULL) {
$build = $this
->viewMultiple([
$entity,
], $view_mode, $langcode);
return $build[0];
}
}