Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyberlex404/dddb0f470015b6a0ef318372ad3c8a75 to your computer and use it in GitHub Desktop.
Save cyberlex404/dddb0f470015b6a0ef318372ad3c8a75 to your computer and use it in GitHub Desktop.
private function getViewRender($views_id, $display_id, $arguments = [], $class = NULL, $is_title = TRUE) {
if(is_null($class)) {
$class = $views_id . '-' .$display_id;
}
$build = [
'#prefix' => '<div class="' . $class . '">',
'#suffix' => '</div>',
];
// get the view machine id
$view = Views::getView($views_id);
// set the display machine id
$view->setDisplay($display_id);
// set arguments/filter values
$view->setArguments($arguments);
// dpm($view->getStyle());
$title = $view->getTitle();
//dpm($title);
if(isset($title) && $is_title) {
$attributes = new Attribute(['class' => ['tab-header']]);
$build['header'] = [
'#type' => 'html_tag',
'#tag' => 'h3',
'#value' => $title,
'#attributes' => $attributes,
];
}
$build['content'] = $view->render();
return $build;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment