Problem/Motivation

After upgrading a D7 site to PHP 8.0, views_embed_view is not loading template.

Steps to reproduce

We are using a template that has this code:
views_embed_view('usercomments', 'block');
And the view has a template "views-view--usercomments--block.tpl.php"
The first time the view is render correctly with this template.
If we reload the page , then the view does not load the template, and paints without template.

Regards,
Jordi
JOINSO

Comments

JOINSO created an issue. See original summary.

damienmckenna’s picture

Issue tags: -#php 8.0 +PHP 8.0

Thank you for reporting this bug.

There are a lot of things that could cause this.

Can you reproduce the problem on a bare install of Drupal 7 with one of the core themes and the default views that are included with the module?

joinso’s picture

Hi!
I cannot reproduce on a bare install of Drupal 7.
If I test the same code in PHP 7.4 it works.
Also, If I clear the cache (memcache) of Drupal in PHP 8.0, the view is rendered correctly with the template.

Regards,
Jordi
JOINSO

damienmckenna’s picture

Can you please upload the view as a text file so we can review it? Are you doing any preprocessing on the output?

joinso’s picture

StatusFileSize
new8.92 KB

I attached the view and the template.

Regards,
Jordi
JOINSO

damienmckenna’s picture

Thanks for posting the view. Can you please post the template too?

joinso’s picture

StatusFileSize
new4.17 KB

Here is the template.

damienmckenna’s picture

Category: Bug report » Support request

I would suggest trying the site with a different theme to see if the problem persists with the default output.

joinso’s picture

I test with Bartik and I have the same issue: the template of the view is not loaded.

Regards,
Jordi
JOINSO

museumboy’s picture

I'm using this script in rules to add a view to an email. It is no longer working now that I'm on php 8.0

damienmckenna’s picture

@museumboy: I suggest reviewing your custom code, there might be something that needs to be fixed in it.

damienmckenna’s picture

Status: Active » Postponed (maintainer needs more info)

@JOINSO: please test the latest dev release, see if it resolves the problem.

joinso’s picture

@DamienMcKenna:
Thanks for the tip.
Few months ago, we released the new version of our site that is working with PHP 8.0 and D7.
Our solution was change this:
echo views_embed_view('usercomments', 'block');
To this:

  $view = views_get_view('usercomments');
  $view->set_display('block');	  
  $view->pre_execute();
  $view->execute();
  if(count($view->result)>0)
  {
		?>
            <div class="view-content">
            <br/><br/><strong><?php echo t('My Reviews');?></strong><br/><br/>
            <table>
              <tr>
                <td>
                  <?php echo t('Review Id');?>
                </td>
                <td>
                  <?php echo t('Edition Date');?>
                </td>
                <td>
                  
                  <?php echo t('Review Preview');?>
                </td>
                <td>
                  <?php echo t('Published on');?>
                </td>
                <td>
                  <?php echo t('Type');?>
                </td>
                <td>
                  <?php echo t('Subscription');?>
                </td>
                <td>                  
                  <?php echo t('Actions');?>
                </td>
              </tr>   
            <?php
            foreach($view->result as $key => $row)
            {
              $nodeComment=node_load($row->comment_nid);
              $commentNotify=array();
              $commentNotify[$row->cid]=(object)[];
              comment_notify_comment_load($commentNotify);
              		    ?>
          		      <tr>
          		        <td>
              	        <?php echo $row->cid;?>
              	      </td>
              	      <td>
              	        <?php echo date("Y-m-d h:i:s",$row->comment_changed);?>
              	      </td>
              	      <td>
              	        <?php echo mysite_tools_truncate_html($row->_field_data['cid']['entity']->comment_body['und'][0]['value'],20);?>
              	        
              	      </td>
              	      <td>
              	        <?php 
              	        echo $nodeComment->title;
              	        ?>
              	      </td>
              	      <td>
              	        <?php echo $nodeComment->type;?>
              	      </td>
              	      <td>
              	        <?php 
              	        if($commentNotify[$row->cid]->notify)
              	        {
              	          echo t('Subscribed');
              	        }
              	        else
              	        {
              	          echo t('Unsubscribed');              	          
              	        }
              	        ?>
              	      </td>
              	      <td>
              	        <a class='linkMyContent' href="/comment/<?php echo $row->cid;?>" target="_new"><?php echo t('View');?></a> | 
              	        <a class='linkMyContent' href="/comment/<?php echo $row->cid;?>/edit" target="_new"><?php echo t('Edit');?></a>
              	      </td>		        
          		      </tr>
              
              <?php
            }	  
            ?>
          	  </table>  
          	  <?php    
		echo theme('pager'); 
  }

At the moment I am not going to make more test because I am focused in migrating D7 to D10.
Hope this workaround can help other ones to fix the issue.
Regards,
Jordi
JOINSO

damienmckenna’s picture

Issue tags: +Needs tests

I noticed that there's no test coverage for views_embed_view(), so let's add some.

damienmckenna’s picture

Status: Postponed (maintainer needs more info) » Active
damienmckenna’s picture

Version: 7.x-3.27 » 7.x-3.x-dev
damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new2.36 KB

A starting point for test coverage on views_embed_view().

damienmckenna’s picture

I've set the tests to run against both PHP 7.4 and 8.0, so we'll see if a basic view works as expected.

damienmckenna’s picture

The test coverage shows the same output working for both PHP 7.4 and 8.0. I suggest you both look into the specific views that are failing for you and see if any of them include custom PHP code, that could be the culprit.

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community
joseph.olstad’s picture

Issue tags: -Needs tests
joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs tests

Oops

damienmckenna’s picture

Status: Needs review » Needs work
StatusFileSize
new1.01 KB

The correct test patch.