You are here

abstract class RendererBase in Views Parity Row 8

Renders entities in the current language.

Hierarchy

Expanded class hierarchy of RendererBase

File

src/Plugin/views/Entity/Render/RendererBase.php, line 12

Namespace

Drupal\views_parity_row\Plugin\views\Entity\Render
View source
abstract class RendererBase extends ViewsRendererBase {

  /**
   * {@inheritdoc}
   */
  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));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RendererBase::$build protected property Contains an array of render arrays, one for each rendered entity.
RendererBase::$entityType protected property The type of the entity being rendered.
RendererBase::$languageManager protected property The language manager.
RendererBase::$view public property The view executable wrapping the view storage entity.
RendererBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts 2
RendererBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
RendererBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
RendererBase::preRender public function Runs before each entity is rendered. Overrides RendererBase::preRender
RendererBase::query abstract public function Alters the query if needed. 2
RendererBase::render abstract public function Renders entity data. 2
RendererBase::__construct public function Constructs a renderer object. 2