Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291302

Return render arrays from RowPluginBase::render overrides

$
0
0

This was observed in changes for #2008980: Replace theme() with drupal_render() in comment module. One of the suggestions was to use parent::render() from \Drupal\comment\Plugin\views\row\Rss, which is inherited from RowPluginBase.

This is the definition of RowPluginBase::render():

  function render($row) {
    return array(
      '#theme' => $this->themeFunctions(),
      '#view' => $this->view,
      '#options' => $this->options,
      '#row' => $row,
      '#field_alias' => isset($this->field_alias) ? $this->field_alias : '',
    );
  }

This gives an impression that render() can return render arrays. This was the rationale behind the suggestion. However, this breaks the system.

The analysis is explained in #2008980-20: Replace theme() with drupal_render() in comment module. The patch which introduced changes to RowPluginBase::render() is at #1811828-77: Use #attached to find the css/js of a view. This is the code in RowPluginBase::render() before the patch.

  function render($row) {
    return theme($this->theme_functions(),
      array(
        'view' => $this->view,
        'options' => $this->options,
        'row' => $row,
        'field_alias' => isset($this->field_alias) ? $this->field_alias : '',
      ));
  }

I currently see two ways to solve this.

  1. Fix the change introduced in #1811828-77: Use #attached to find the css/js of a view but use drupal_render instead of the original theme() call.
  2. Fix the following foreach loop in \Drupal\views\Plugin\views\style\Rss to support arrays, not just strings.
        foreach ($this->view->result as $row_index => $row) {
          $this->view->row_index = $row_index;
          $rows .= $this->view->rowPlugin->render($row);
        }

I am inclined towards the second approach as we are moving towards render arrays for passing data around. However, I am not entirely sure what Render API element would be the best fit here. I will post a patch as soon as I figure that out. Meanwhile, please suggest on other methods or solutions.


Viewing all articles
Browse latest Browse all 291302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>