views_embed_view not loading template in PHP 8.0

Created on 20 October 2022, about 2 years ago
Updated 20 December 2023, 12 months ago

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

πŸ’¬ Support request
Status

Needs review

Version

3.0

Component

Miscellaneous

Created by

πŸ‡ͺπŸ‡ΈSpain JOINSO Sabadell

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • πŸ‡ΊπŸ‡ΈUnited States museumboy

    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

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

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

  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

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

  • πŸ‡ͺπŸ‡ΈSpain JOINSO Sabadell

    @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 f4r_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

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

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

  • Status changed to Active over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    230 pass
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    A starting point for test coverage on views_embed_view().

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 7.x + Environment: PHP 7.4 & MySQL 5.5
    last update over 1 year ago
    230 pass
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    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.

  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    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.

  • Status changed to RTBC 12 months ago
  • Status changed to Needs review 12 months ago
Production build 0.71.5 2024