silverstripe / silverstripe-versioned-admin

Provides admin UIs for versioned DataObjects in Silverstripe CMS.
BSD 3-Clause "New" or "Revised" License
9 stars 28 forks source link

Warning on /admin/archive/DNADesign-Elemental-Models-BaseElement (Blocks tab) #314

Open elliot-sawyer opened 1 year ago

elliot-sawyer commented 1 year ago

Latest CMS Recipe 4.13.0:

[Warning] foreach() argument must be of type array|object, null given
GET /admin/archive/DNADesign-Elemental-Models-BaseElement

Line 3922 in /var/www/html/vendor/silverstripe/framework/src/ORM/DataObject.php

Somehow I have BaseElement.summary_fields set to null, which is weird given there's a private static $summary_fields value set on that class that isn't null. While I am unsure what causes it, it may be related to an obsolete ClassName that remains in the database. Via debugging, I found one solution is to adjust the DataObject::summaryFields() method to force an array:

Changing $rawFields = $this->config()->get('summary_fields'); to this: $rawFields = $this->config()->get('summary_fields') ?? [];

Another option, if PHP support is a concern, is to check if the array is falsey:

        $rawFields = $this->config()->get('summary_fields');

        // Merge associative / numeric keys
        $fields = [];
        if(!$rawFields) {
            return $fields;
        }

I reached out to @GuySartorelli on Slack and he said this is unlikely to be accepted without an identifiable cause, so I'm going to post the issue here in case anyone else comes across it.

elliot-sawyer commented 1 year ago

In case anyone else finds this issue, I fixed it in project code by setting this in YML. These are the original values defined on BaseElement, being reset to an array with values in case it is null. If the code is not null, this array_merge is effectively a no-op:

DNADesign\Elemental\Models\BaseElement:
  summary_fields:
    EditorPreview: Summary