Return render arrays from RowPluginBase::render overrides

Created on 19 June 2013, almost 12 years ago
Updated 30 August 2023, over 1 year ago

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.

📌 Task
Status

Closed: outdated

Version

9.5

Component
Views 

Last updated about 4 hours ago

Created by

🇨🇦Canada hussainweb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024