public function TagViewBuilder::viewMultiple in Doubleclick for Publishers (DFP) 8
Builds the render array for the provided entities.
Parameters
array $entities: An array of entities implementing EntityInterface to view.
string $view_mode: (optional) The view mode that should be used to render the entity.
string $langcode: (optional) For which language the entity should be rendered, defaults to the current content language.
Return value
A render array for the entities, indexed by the same keys as the entities array passed in $entities.
Throws
\InvalidArgumentException Can be thrown when the set of parameters is inconsistent, like when trying to view Comments and passing a Node which is not the one the comments belongs to, or not passing one, and having the comments node not be available for loading.
Overrides EntityViewBuilder::viewMultiple
1 call to TagViewBuilder::viewMultiple()
- TagViewBuilder::view in src/
View/ TagViewBuilder.php - Builds the render array for the provided entity.
File
- src/
View/ TagViewBuilder.php, line 119 - Contains \Drupal\dfp\View\TagViewBuilder.
Class
- TagViewBuilder
- Provides a DFP Tag view builder.
Namespace
Drupal\dfp\ViewCode
public function viewMultiple(array $entities = [], $view_mode = 'full', $langcode = NULL) {
/** @var \Drupal\dfp\Entity\TagInterface[] $entities */
$build = [];
foreach ($entities as $tag) {
// @todo Ensure a tag is only once on the page.
// @todo Get cache-ability based on tokens used in TagView...
$global_settings = $this->configFactory
->get('dfp.settings');
$tag_view = new TagView($tag, $global_settings, $this->token, $this
->moduleHandler());
$tag_id = $tag
->id();
$build[$tag_id] = [
'#cache' => [
'keys' => [
'entity_view',
'dfp_tag',
$tag_id,
],
],
];
// Sort out the cache tags and contexts.
$cacheable_metadata = CacheableMetadata::createFromObject($global_settings);
$cacheable_metadata
->merge(CacheableMetadata::createFromObject($tag));
$cacheable_metadata
->addCacheTags($this
->getCacheTags());
$cacheable_metadata
->applyTo($build[$tag_id]);
$build[$tag_id] += static::buildPreTag($tag_view);
}
return $build;
}