When no WOTD is set, the WOTD feed view crashes

Created on 30 June 2023, over 1 year ago
Updated 9 July 2023, over 1 year ago

Problem/Motivation

When no WOTD is set, which should not happen, displaying the WOTD feed triggers an exception.

Steps to reproduce

install a fresh drupal
add G2
navigate to /g2/feed/wotd

Observe:

The website encountered an unexpected error. Please try again later.<br /><em class="placeholder">Error</em>: Attempt to modify property &quot;_entity&quot; on null in <em class="placeholder">Drupal\g2\WOTD-&gt;viewsPreRender()</em> (line <em class="placeholder">261</em> of <em class="placeholder">modules/contrib/g2/src/WOTD.php</em>). <pre class="backtrace">Drupal\g2\WOTD-&gt;viewsPreRender(Object) (Line: 154)
g2_views_pre_render(Object)
call_user_func_array(Object, Array) (Line: 426)
Drupal\Core\Extension\ModuleHandler-&gt;Drupal\Core\Extension\{closure}(Object, &#039;g2&#039;) (Line: 405)
Drupal\Core\Extension\ModuleHandler-&gt;invokeAllWith(&#039;views_pre_render&#039;, Object) (Line: 433)
Drupal\Core\Extension\ModuleHandler-&gt;invokeAll(&#039;views_pre_render&#039;, Array) (Line: 1528)
Drupal\views\ViewExecutable-&gt;render() (Line: 128)
Drupal\views\Plugin\views\display\Feed-&gt;execute() (Line: 1635)
Drupal\views\ViewExecutable-&gt;executeDisplay(&#039;feed_1&#039;, Array) (Line: 81)
Drupal\views\Element\View::preRenderViewElement(Array)
...snip...

Proposed resolution

The problem happens because WOTD::viewsPreRender() assumes the view result exists. Harden it against missing results.

Remaining tasks

Do it.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇫🇷France fgm Paris, France

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

Comments & Activities

Production build 0.71.5 2024