When removing a paragraph on PHP 7.2 I'm getting:

Warning: count(): Parameter must be an array or an object that implements Countable in paragraphs_field_widget_embed_validate() (line 712 of paragraphs/paragraphs.field_widget.inc).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jacob.embree created an issue. See original summary.

bramvandenbulcke’s picture

I also had this issue on a Drupal 7 install with PHP 7.2.

At the moment I'm able to bump my Drupal 7 installs to PHP 7.1. Some smaller issues on Paragraphs and Date are holding me back to move to PHP 7.2. I hope this patch will get in eventually.

jacob.embree’s picture

To me the first patch makes more sense than #3. The intention of the statement really is to check if the value is empty. The count itself is not important, so it isn't necessary to check if it is some sort of countable.

jacob.embree’s picture

Nevermind about #4. I just read the comment in _form_validate():

// A simple call to empty() will not cut it here as some fields, like
// checkboxes, can return a valid value of '0'. Instead, check the
// length if it's a string, and the item count if it's an array.
// An unchecked checkbox has a #value of integer 0, different than string
// '0', which could be a valid value.

#3 looks good, but I haven't manually tested it.

klausi’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested, makes sense!

skylord’s picture

#3 works OK, thanks. Commit and new release are must have as php5 is deprecated now...

banoodle’s picture

Hi and thanks for the patch!

Can someone provide me with details on how to reproduce this warning? Above it says "When removing a paragraph" but I'm not clear what exactly that means.

I have tried removing a paragraph from a node, from a content type and from the site, but none of those things generated the waring.

We're not seeing this warning (and we have all warnings/errors and logging enabled) and I would ideally like to reproduce the warning prior to patching.

I know I may sound overly cautious, but this is for a very complex and highly customized site, so I really like to be sure I'm scrutinizing the right part of the module's functionality so as to not introduce new problems.

bramvandenbulcke’s picture

@banoodle: sure PHP 7.2 is running on your site? Check your status report to see the active PHP version.

Christian DeLoach’s picture

This error message started appearing for me as soon as I added a link field (https://www.drupal.org/project/link) to my paragraph. When I remove the field the error goes away. Add the field back in and the error returns. The error only appears when the link field has a value. When the link fields are empty, the error does not appear.

donaldwbabcock’s picture

#3 works on my 7.x-1.x-RC5 running on php7.2.

Just a comment, I've seen two implementations of "$is_empty_multiple" between D7Core and in various modules. Core currently uses count($elements['#value']) == 0; where as this patch uses (!count($elements['#value']));.

See https://api.drupal.org/api/drupal/includes%21form.inc/function/_form_val...

The result is the correct true or false in both cases, but we have a note in this function that this code came from _form_validate, so some consistency may be in order.

Either way, RTBC, as we need some of these php7.x related little changes committed and either RC6 rolled, or a final 7.x-1.0 rolled.

jenlampton’s picture

+1 for RTBC

interdruper’s picture

Same case use as #10. Patch #3 removes de warning on PHP 7.2. IMHO, RTBC.

bradallenfisher’s picture

I was having this error when any nested paragraph fields were set to required.
just applied the patch in #3 manually, and it stops the warning. Drupal 7.67 - PHP 7.2 on Acquia cloud enterprise.

Thanks. didn't try first patch. so it may work also.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

I committed this change to clean-up the queue. Thx all for pushing. :-)

Status: Fixed » Closed (fixed)

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