adrianbj / TracyDebugger

The ultimate debugging and development tool for ProcessWire
https://adrianbj.github.io/TracyDebugger/
GNU General Public License v2.0
88 stars 13 forks source link

PageFilesPanel error for Repeater Matrix pages #61

Closed Toutouwai closed 3 years ago

Toutouwai commented 3 years ago

When editing a page that contains a Repeater Matrix field I get an error in the Page Files panel:

ErrorException: Invalid argument supplied for foreach() in D:\_Websites\_www\1testing\site\assets\cache\FileCompiler\site\modules\TracyDebugger\panels\PageFilesPanel.php:232

I did some quick debugging and the issue seems to relate to files/images fields that are allowed for one matrix type but not another matrix type.

In PageFilesPanel.php you have...

// ...
 elseif($f && $f->type instanceof FieldTypeFile) {
    foreach($p->{$f->name} as $file) {
// ...

...which would be fine normally because a field that is an instance of FieldtypeFile (sidenote: you might want to search Tracy for occurrences of "FieldType" which is the wrong capitalisation) will normally return a WireArray when output formatting is off. But Repeater Matrix returns null for fields that exist in the matrix template but do not exist in the matrix type of a given matrix page. Refer to RepeaterMatrixPage::getField()

So maybe add an extra check that the field value is truthy?

elseif($f && $f->type instanceof FieldTypeFile && $p->{$f->name}) {
// ...
adrianbj commented 3 years ago

Thanks @Toutouwai for the detailed debugging and also catching that cache issue. All should be fixed in the latest version.

Toutouwai commented 3 years ago

Thanks!