Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
elliot-sawyer opened this issue Oct 25, 2023 · 1 comment

Comments

@elliot-sawyer
Copy link

elliot-sawyer commented Oct 25, 2023

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
Copy link
Author

elliot-sawyer commented Oct 25, 2023

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

@elliot-sawyer elliot-sawyer changed the title Warning on /admin/archive/DNADesign-Elemental-Models-BaseElement Warning on /admin/archive/DNADesign-Elemental-Models-BaseElement (Blocks tab) Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants