Problem/Motivation

PHP Fatal error: Declaration of Drupal\\webform\\Plugin\\Field\\FieldFormatter\\WebformEntityReferenceFormatterBase::getEntitiesToView(Drupal\\Core\\Field\\EntityReferenceFieldItemListInterface $items, $langcode) must be compatible with Drupal\\Core\\Field\\Plugin\\Field\\FieldFormatter\\EntityReferenceFormatterBase::getEntitiesToView(Drupal\\Core\\Field\\FieldItemListInterface $items, $langcode) in /home/jenkins/workspace/D9_SANDBOX_LILY_STANDARD_VIRTUAL_Y/build/docroot/modules/contrib/webform/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php on line 60

Steps to reproduce

Drush install profile with webform module added as a dependency

Proposed resolution

Fix

Remaining tasks

Review/Merge/Release

User interface changes

No

API changes

No

Data model changes

No

Issue fork webform-3305679

Command icon 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

podarok created an issue. See original summary.

podarok’s picture

Status: Active » Needs review
StatusFileSize
new125.2 KB

Tested as works good on
Drupal 9.4.5
PHP 8.1.9
MySQL 5.7.39
YUSA CodeShare distribution ( former Open Y ) - 9.2.1.15

More details
Added patch via composer from current issue MR https://github.com/YCloudYUSA/yusaopeny/commit/727a18c30929c799713fb379d...
Fixed same issue for video module - see https://www.drupal.org/project/video/issues/3305673 and released 3.0.1 video module

podarok’s picture

Assigned: podarok » Unassigned
podarok’s picture

Priority: Normal » Major

Marking as critical because it blocks installation

anpolimus’s picture

@podarok code is ok, but now it looks like we have to add additional code to the info file saying that Webform 6.1.3+ requires Drupal 9.4.
Or we could add it to the composer.
PR fixes the issue on fresh install with 9.4

anpolimus’s picture

Status: Needs review » Reviewed & tested by the community
jrockowitz’s picture

Title: PHP Fatal error: Declaration of WebformEntityReferenceFormatterBase::getEntitiesToView » [Drupal 9.4] PHP Fatal error: Declaration of WebformEntityReferenceFormatterBase::getEntitiesToView
froboy’s picture

Adding duplicate issue, will leave this as the primary.

froboy’s picture

@anpolimus I'm not sure if the requirements have changed, but Webform 6.1.3 requires Drupal ^9 but Webform ^6.2 requires Drupal ^9.4. This patch can work with either version, and coercing Webform to a different version can cause errors:

The following module is installed, but it is incompatible with Drupal 9.3.22:
Webform

I think we should remove the Drupal version change and leave that up to Webform to decide.

podarok’s picture

+1 #10

froboy’s picture

Fixed that up and rebased.

froboy’s picture

Reproduction steps:

- Install Drupal Core 9.4.5 (with Umami profile)
- Enable All messages at /admin/config/development/logging
- Require and enable Webform
- Edit a content type and add a Webform Reference field
- Upon trying to Save the Add field dialog, observe the error:

Fatal error: Declaration of Drupal\webform\Plugin\Field\FieldFormatter\WebformEntityReferenceFormatterBase::getEntitiesToView(Drupal\Core\Field\EntityReferenceFieldItemListInterface $items, $langcode) must be compatible with Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceFormatterBase::getEntitiesToView(Drupal\Core\Field\FieldItemListInterface $items, $langcode) in /var/www/html/web/modules/contrib/webform/src/Plugin/Field/FieldFormatter/WebformEntityReferenceFormatterBase.php on line 60

I'm not able to recreate this with Drupal 10.0.1 and Webform 6.2, but not sure why as none of the related files seem to have changed.

jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work
froboy’s picture

Status: Needs work » Postponed

@jrockowitz 🤦🏻‍♂️ I think I need environment_indicator on my DrupalPod. The environment in which I was able to reproduce the issue DID have the patch from #3138528: getEntitiesToView() should implements the same interface as viewElements() applied.

At this point it seems like that issue might be going a different direction, so I think we can mark this Postponed until the parent issue is somehow resolved. Sorry for the confusion and thanks for your time.

josedsilva’s picture

Thanks @jrockowitz
Removing the patch: #3138528: getEntitiesToView() should implements the same interface as viewElements() and updating core with `composer update --lock` fixed the "PHP Fatal error: Declaration of WebformEntityReferenceFormatterBase::getEntitiesToView" issue for me.

jrockowitz’s picture

Title: [Drupal 9.4] PHP Fatal error: Declaration of WebformEntityReferenceFormatterBase::getEntitiesToView » [Drupal core] PHP Fatal error: Declaration of WebformEntityReferenceFormatterBase::getEntitiesToView
Version: 6.1.3 » 6.2.x-dev

Removing the Drupal specific version number since this is a Drupal core related issue that has not being resolved.

jrockowitz’s picture

Version: 6.2.x-dev » 6.3.x-dev