public function RendererBase::preRender in Views Parity Row 8
Runs before each entity is rendered.
Parameters
$result: The full array of results from the query.
Overrides RendererBase::preRender
File
- src/
Plugin/ views/ Entity/ Render/ RendererBase.php, line 17
Class
- RendererBase
- Renders entities in the current language.
Namespace
Drupal\views_parity_row\Plugin\views\Entity\RenderCode
public function preRender(array $result) {
$view_builder = $this->view->rowPlugin
->getEntityTypeManager()
->getViewBuilder($this->entityType
->id());
$previous_pages_item_count = $this->view->pager
->getCurrentPage() * $this->view->pager
->getItemsPerPage();
$options = $this->view->rowPlugin->options;
/** @var \Drupal\views\ResultRow $row */
foreach ($result as $row) {
$entity = $row->_entity;
$view_mode = $options['view_mode'];
$current_item = $previous_pages_item_count + $row->index;
if ($options['views_parity_row_enable']) {
$view_mode_override = FALSE;
if ($current_item >= $options['views_parity_row']['start']) {
if ($options['views_parity_row']['end'] !== '0') {
if ($current_item < $options['views_parity_row']['end']) {
$view_mode_override = TRUE;
}
}
else {
$view_mode_override = TRUE;
}
}
if ($view_mode_override) {
if (($current_item - $options['views_parity_row']['start']) % $options['views_parity_row']['frequency'] === 0) {
$view_mode = $options['views_parity_row']['view_mode'];
}
}
}
if ($options['views_parity_row_per_row_enable'] && !empty($options['views_parity_row_per_row']['view_mode_' . ($current_item + 1)])) {
$view_mode = $options['views_parity_row_per_row']['view_mode_' . ($current_item + 1)];
}
$this->build[$entity
->id()] = $view_builder
->view($entity, $view_mode, $this
->getLangcode($row));
}
}