When saving a node with an empty Range field, I get the following error message:

Notice: Trying to access array offset on value of type null in Drupal\range\Plugin\Field\FieldWidget\RangeWidget->formElement() (line 151 of [...]/modules/contrib/range/src/Plugin/Field/FieldWidget/RangeWidget.php) 

The error also occurs in line 152.

I am using Range 1.2 in Drupal 8.9.0 with PHP 7.4.6. The error does not occur in PHP 7.3, and it does not occur if I downgrade to Range 1.1.

Comments

David Radcliffe created an issue. See original summary.

david radcliffe’s picture

Title: Trying to access array offset on value of type nul (PHP 7.4) » Trying to access array offset on value of type null (PHP 7.4)
taran2l’s picture

Status: Active » Postponed (maintainer needs more info)

hi @David Radcliffe - thanks or the issue but I'm not able to reproduce it... Could you provide more details?

  • Have you installed a module as a new one?
  • Have you updated from 8.x-1.1 ?
  • Have you run updates & cleared the caches?
david radcliffe’s picture

I was unable to reproduce the issue on a new Drupal site. Perhaps I forgot to run the update script.

david radcliffe’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
hugronaphor’s picture

Status: Closed (cannot reproduce) » Needs work

I do have the same issue and most likely the reason behind it is the fact that .module file has only been added in 1.2 version.

The issue is more about Drupal core, if you have a module enabled without a .module adding it later won't be picked up by Drupal( see this discussion )

I didn't find a solution through hook_update to this use-cases but there should be a way.

We need a programmatical fix instead of re-enabling the module as in my case I have lots of dependencies on this module and uninstalling it would cause more unwanted consequences.

gmarineau’s picture

I have the same issue any update or solution for this bug.

gmarineau’s picture

I have the same issue any update or solution for this bug.

john.oltman’s picture

StatusFileSize
new1.15 KB

See attached patch for the fix. As noted previously, the notice only occurs in PHP 7.4 because of its stricter checking, although the logic involved was not ideal for any version. The prefix and suffix were added in 8.x-1.2 and therefore the bug only exists in that version.

john.oltman’s picture

Status: Needs work » Needs review
murz’s picture

Thanks for patch, it works well and fix the issue! Will be good to see it in module core!

taran2l’s picture

StatusFileSize
new12.21 KB

Hi everyone, thanks for pushing on this issue. In the end, I was able to reproduce the issue.

Test only patch is attached.

Status: Needs review » Needs work

The last submitted patch, 12: range-3150297-12-test-only.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

taran2l’s picture

Status: Needs work » Needs review
StatusFileSize
new13.24 KB

@john.oltman, your patch fixes the issue, but here is a more elegant/shorter approach

Status: Needs review » Needs work

The last submitted patch, 14: range-3150297-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

taran2l’s picture

Status: Needs work » Needs review
Related issues: +#3180038: Fix recently introduced Drupal 9 deprecations

So, HEAD now passes all tests, let's re-run the latest patch

taran2l’s picture

Status: Needs review » Reviewed & tested by the community

  • Taran2L committed dad5edc on 8.x-1.x
    fix(widget) Fix 'Trying to access array offset on value of type null in...
taran2l’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.