Problem/Motivation

Encountered deprecation errors while using this module with PHP 8.5:

Deprecated function: Using null as an array offset is deprecated, use an empty string instead in Drupal\entity_embed\EntityEmbedDisplay\FieldFormatterEntityEmbedDisplayBase->build() (line 140 of /var/www/html/web/modules/contrib/entity_embed/src/EntityEmbedDisplay/FieldFormatterEntityEmbedDisplayBase.php)

Steps to reproduce

  1. Upgrade to PHP 8.5
  2. View content containing embedded entities
  3. Find deprecation error(s) in logs

(See https://www.php.net/manual/en/migration85.deprecated.php#migration85.dep...)

Proposed resolution

Fallback to empty string as array index if $fakeEntity->id() is null in FieldFormatterEntityEmbedDisplayBase::build().

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#5 3577405-mr66-5.patch935 bytesjoegraduate
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

joegraduate created an issue. See original summary.

joegraduate’s picture

Assigned: joegraduate » Unassigned
Status: Active » Needs review
joegraduate’s picture

Confirmed that example below works for both PHP 8.3 and 8.5:

php > $test = [];
php > $test[NULL]['a'] = 'x';
php > $test[NULL]['b'] = 'y';
php > $test['']['c'] = 'z';
php > print_r($test);
Array
(
    [] => Array
        (
            [a] => x
            [b] => y
            [c] => z
        )

)

Based on these results I believe that the change in MR !66 should preserve the existing functionality (and fix the deprecation errors/warnings on PHP 8.5).

joegraduate’s picture

StatusFileSize
new935 bytes

Adding current diff from MR as patch file for composer.

liam morland’s picture

Issue tags: -PHP 8.* deprecation
jmagunia’s picture

Patch in Comment #5 worked. Thank you