silverstripe / silverstripe-widgets

Widgets subsystem for Silverstripe CMS
http://silverstripe.org
BSD 3-Clause "New" or "Revised" License
38 stars 55 forks source link

[Warning] Invalid argument supplied for foreach() on 1.3 release running on SS 3.* #175

Closed sinan-evanshunt closed 6 years ago

sinan-evanshunt commented 6 years ago

On 1.3. release (SilverStripe 3.) I get an error:

[Warning] Invalid argument supplied for foreach()

Line 53 in widgets/code/form/WidgetAreaEditor.php
Source

45             $classes = ClassInfo::subclassesFor($widgetClass);
46 
47             if (isset($classes['Widget'])) {
48                 unset($classes['Widget']);
49             } elseif (isset($classes[0]) && $classes[0] == 'Widget') {
50                 unset($classes[0]);
51             }
52 
53                 foreach ($classes as $class) {
54                     $available = Config::inst()->get($class, 'only_available_in');
55 
56                     if (!empty($available) && is_array($available)) {
57                         if (in_array($this->Name, $available)) {
58                             $widgets->push(singleton($class));
69                         }

Wrapping the foreach with if( isset($classes) ) fixes the issue for me. Not sure if this is the proper fix or if there is a deeper issue.

NightJar commented 6 years ago

Hi @sinan-evanshunt - this issue is caused by not having any widgets installed with this module. This could probably be resolved by changing line 45 to $classes = ClassInfor::subclassesFor($widgetClass) ?: array();

How would you feel about raising a pull request to the 1.3 branch of this repository with the fix?

NightJar commented 6 years ago

Oh, I see you already have raised a PR at #176