When files are uploaded via ajax and validation happens on the form, PHP 7 will throw a PHP notice on the following code:

elseif ($elements['#type'] == 'select' && !$elements['#multiple'] && $elements['#required'] && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) {

To prevent the PHP notice, I've changed it as follows:

elseif ($elements['#type'] == 'select' && $elements['#required'] && (!array_key_exists('#multiple', $elements) || !$elements['#multiple']) && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) {

Steps to reproduce:
* run the latest version of Drupal 7 on PHP 7.1
* install file entity module
* add fields to your image type file
* create an article
* upload an image (see the PHP notice after the image is uploaded via ajax)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jenlampton created an issue. See original summary.

jenlampton’s picture

Status: Active » Needs review

Setting status to NR

jenlampton’s picture

Patch still cleanly applies to 7.74.

izmeez’s picture

Title: PHP notice thrown on PHP 7 » Ajax upload with validation throws PHP notice on PHP 7

Updated issue title for clarity

jenlampton’s picture

Patch still cleanly applies to 7.75.

izmeez’s picture

Added to #3179845: [meta] Priorities for 2020-12-02 bugfix release of Drupal 7.76 / 7.77, won't get into next release but may help raise it's visibility.

jenlampton’s picture

Thanks for the update @izmeez! Patch still cleanly applies to 7.78.

izmeez’s picture

This issue is included in the new meta issue #3192080: [meta] Priorities for 2021-04-07 release of Drupal 7

jenlampton’s picture

Patch still applies to 7.80, 7.81, and 7.82.

mcdruid’s picture

Status: Needs review » Reviewed & tested by the community

I wasn't able to reproduce the PHP Notices with file_entity and PHP 7(.4) - quite likely that I wasn't following the steps correctly.

However, the change looks reasonable - if this prevents Notices under some circumstances, that's an improvement.

  • mcdruid committed 9e1ecd6 on 7.x
    Issue #3002101 by jenlampton: Ajax upload with validation can cause PHP...
mcdruid’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +PHP 7.0 (duplicate)

Thank you!

Status: Fixed » Closed (fixed)

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