Problem/Motivation
If a View has a date field added to it that is NULL, the following error triggers :
Deprecated function: strtotime(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\view_custom_table\Plugin\views\field\MysqlDate->render() (line 154 of /var/www/html/web/modules/contrib/view_custom_table/src/Plugin/views/field/MysqlDate.php)
This is due to the fact that if no date is set, $date_value ends up as NULL (which then gets passed on to strtime) :
public function render(ResultRow $values) {
$date_value = $this->getValue($values);
$value = strtotime($date_value);
..
This is only from PHP 8.1 onwards, as 8.1 has deprecated passing null to a lot of functions (see here).
Steps to reproduce
- Create a database table with a date field, that is allowed to be set to NULL. Make sure the table has at least a single entry with a date of NULL
- Add the new database table as a Views Custom Table
- Create a View based on this new Views Custom Table, and add the date field to it
- Preview the View
Proposed resolution
Check that $date_value is not NULL before continuing the render function.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | view_custom_table-3316433-4.patch | 6.09 KB | bogdan.dinu |
Issue fork view_custom_table-3316433
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
joseph.olstadsee changes in the HEAD of 2.0.x and in the 2.0.3 release
Comment #4
bogdan.dinu commentedThis is still an issue because there is no check on the value that is given to strtotime on line 155.
I attached a patch with a fix.
Comment #5
liam morlandComment #7
shivam_tiwari commentedComment #9
shivam_tiwari commentedComment #10
avpadernoComment #11
joseph.olstadComment #12
joseph.olstadMerge request is 7 commits behind and is blocked
Comment #13
shivam_tiwari commentedComment #14
joseph.olstad