PHP Notice: Received a non-array content with layerState 3

Created on 20 October 2022, over 2 years ago
Updated 22 April 2025, 6 days ago

Problem/Motivation

When i access to entity log operations I receive this warning:

This problem is caused by the LogEntityOperationsJSONCollapsibleFormatter formatter when it receives a field value array which first value is an array, and the rest ones are scalar values.

This problem can be reproduced with image_crop_widget module, which enables the image_crop property, example:

(
    [image_crop] => Array
        (
            [crop_wrapper] => Array
                (
                    [1_1] => Array
                        (
                            [crop_container] => Array
                                (
                                    [reset] => Reset crop
                                )

                        )

                )

            [file-uri] => XXXXXX
            [file-id] => 877
        )

    [display] => 1
    [upload_button] => Upload
    [remove_button] => Remove
    [target_id] => 877
    [alt] => XXXXXX
    [width] => 1426
    [height] => 850
)

As it can be seen the property has its first value as an array, and then it has scalar values.

Steps to reproduce

  • Enable entity operation logs entity
  • Enable diff in entity operation logs
  • Configure the site to use image_widget_crop contrib module.
  • Create content that contains a media image with crops.
  • Go to view the list of entity operation logs : Config > Development > Log Entity Operations > Entity Logs

Then , when you go to view the logs (s.e.: dblog) , you must see the warning.

Proposed resolution

When the LogEntityOperationsJSONCollapsibleFormatter formatter receives a list with mixed values, when one of the values is scalar, add the value as value_layer. Keep throwing the warning when there are other data types such as objects to decide what to do in that case when it occurs (not probable).

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇪🇸Spain omarlopesino

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India nikunjkotecha India, Gujarat, Rajkot

    This is more like image_widget_crop is not having proper format of data, I am happy to add the code but it should be marked as contrib module support (or category support)

    Do you agree? If no, please share Drupal CORE example.

  • 🇪🇸Spain omarlopesino

    After reviewing this issue back, I agree that image_widget_crop is setting up "arbitrary properties" into the field value for convenience. That is the way the module is able to save the list of crops, to save it properly on entity save.

    That is a specific behaviour that I think it won't be present on Drupal core, so I agree it belongs to contrib support.

    However, I noticed something. This problem is happening because a contrib module is setting a property to a field value which won't be saved. In this case, that property won't be saved to database. I mean, if the entity is loaded, that `image_crop` property won't be present.

    I will check if it is possible to solve this problem with other solution: loading the entity before saving the diff here, like it is done at entity update

Production build 0.71.5 2024