protected function ViewsEmbedFilter::buildViewsEmbed in Views entity embed 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Filter/ViewsEmbedFilter.php \Drupal\views_entity_embed\Plugin\Filter\ViewsEmbedFilter::buildViewsEmbed()
Method that build data attributes per node.
1 call to ViewsEmbedFilter::buildViewsEmbed()
- ViewsEmbedFilter::process in src/
Plugin/ Filter/ ViewsEmbedFilter.php - Performs the filter processing.
File
- src/
Plugin/ Filter/ ViewsEmbedFilter.php, line 114
Class
- ViewsEmbedFilter
- Provides a filter to display embedded entities based on data attributes.
Namespace
Drupal\views_entity_embed\Plugin\FilterCode
protected function buildViewsEmbed($node) {
$view_name = $node
->getAttribute('data-view-name');
$view_display = $node
->getAttribute('data-view-display');
$view_attr = Json::decode($node
->getAttribute('data-view-arguments'));
$view = Views::getView($view_name);
$view
->setDisplay($view_display);
if ($view_attr['override_title']) {
$view
->setTitle($view_attr['title']);
}
if (!empty($view_attr['filters'])) {
$view_filters = array_filter($view_attr['filters'], function ($k) use ($view_attr) {
return $view_attr['filters'][$k];
}, ARRAY_FILTER_USE_KEY);
$view
->setArguments($view_filters);
}
// Ensure that views default executions are run. These ensure that view
// display settings such as "use_ajax" are actually read and respected.
$view
->preExecute();
$view
->execute();
$build = [
'#theme_wrappers' => [
'views_entity_embed_container',
],
'#attributes' => [
'class' => [
'views-entity-embed',
],
],
'#view' => $view,
'#context' => [
'data-view-name' => $view_name,
'data-view-display' => $view_display,
'data-override-title' => $view_attr['override_title'],
'data-title' => $view_attr['title'],
],
];
return $build;
}