function DisplayPluginBase::elementPreRender
Same name in other branches
- 9 core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::elementPreRender()
- 8.9.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::elementPreRender()
- 11.x core/modules/views/src/Plugin/views/display/DisplayPluginBase.php \Drupal\views\Plugin\views\display\DisplayPluginBase::elementPreRender()
Overrides DisplayPluginInterface::elementPreRender
File
-
core/
modules/ views/ src/ Plugin/ views/ display/ DisplayPluginBase.php, line 2225
Class
- DisplayPluginBase
- Base class for views display plugins.
Namespace
Drupal\views\Plugin\views\displayCode
public function elementPreRender(array $element) {
$view = $element['#view'];
$empty = empty($view->result);
// Force a render array so CSS/JS can be attached.
if (!is_array($element['#rows'])) {
$element['#rows'] = [
'#markup' => $element['#rows'],
];
}
$element['#header'] = $view->display_handler
->renderArea('header', $empty);
$element['#footer'] = $view->display_handler
->renderArea('footer', $empty);
$element['#empty'] = $empty ? $view->display_handler
->renderArea('empty', $empty) : [];
$element['#exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : [];
$element['#more'] = $view->display_handler
->renderMoreLink();
$element['#feed_icons'] = !empty($view->feedIcons) ? $view->feedIcons : [];
if ($view->display_handler
->renderPager()) {
$exposed_input = $view->getExposedInput();
$element['#pager'] = $view->renderPager($exposed_input);
}
if (!empty($view->attachment_before)) {
$element['#attachment_before'] = $view->attachment_before;
}
if (!empty($view->attachment_after)) {
$element['#attachment_after'] = $view->attachment_after;
}
// If form fields were found in the view, reformat the view output as a form.
if ($view->hasFormElements()) {
// Only render row output if there are rows. Otherwise, render the empty
// region.
if (!empty($element['#rows'])) {
$output = $element['#rows'];
}
else {
$output = $element['#empty'];
}
$form_object = ViewsForm::create(\Drupal::getContainer(), $view->storage
->id(), $view->current_display, $view->args);
$form = \Drupal::formBuilder()->getForm($form_object, $view, $output);
// The form is requesting that all non-essential views elements be hidden,
// usually because the rendered step is not a view result.
if ($form['show_view_elements']['#value'] == FALSE) {
$element['#header'] = [];
$element['#exposed'] = [];
$element['#pager'] = [];
$element['#footer'] = [];
$element['#more'] = [];
$element['#feed_icons'] = [];
}
$element['#rows'] = $form;
}
return $element;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.