Pennebaker / craftcms-thearchitect

CraftCMS plugin to generate content models from JSON data.
MIT License
171 stars 9 forks source link

PHP notice - Undefined index: sources when exporting asset fields #44

Closed ldstevens closed 7 years ago

ldstevens commented 7 years ago

Hi, thanks for The Architect, it's been super useful for my current project 🙏

I'm getting the following error when exporting asset fields in 1.6.0:

PHP notice

Undefined index: sources

[path to craft]/craft/plugins/thearchitect/services/TheArchitectService.php(2879)

---
             foreach ($reasonsOr as &$reason) {
                 $reason['fieldId'] = craft()->fields->getFieldById($reason['fieldId'])->handle;
             }
         }
     }

     return $newReasons;
 }

 private function parseFieldSources(&$field, &$newField)
 {
     if ($field->type == 'Assets') {
         if ($newField['typesettings']['sources'] !== '*') {
             foreach ($newField['typesettings']['sources'] as $key => $value) {
                 if (substr($value, 0, 7) == 'folder:') {
                     $source = craft()->assetSources->getSourceById(intval(substr($value, 7)));
                     if ($source) {
                         $newField['typesettings']['sources'][$key] = $source->handle;
                     }
                 }
             }
         }
         if (isset($newField['typesettings']['defaultUploadLocationSource']) && $newField['typesettings']['defaultUploadLocationSource']) {
             $source = craft()->assetSources->getSourceById(intval($newField['typesettings']['defaultUploadLocationSource']));
             if ($source) {

and wrapping:

if (isset($newField['typesettings']['sources'])) { ... }

around:

if ($newField['typesettings']['sources'] !== '*') {...}

...gets rid of the error for me, but if there's something more fundamental going on, please let me know :)

spAnser commented 7 years ago

This could be one I missed.

The correct fix would probably be changing

if (isset($newField['typesettings']['sources'])) { ... }

to

if (isset($newField['typesettings']['sources']) && is_array(isset($newField['typesettings']['sources']))) { ... }