demianturner / sgl-docs-tickets-migration-test

0 stars 0 forks source link

blockform::classAvailable should use file_exists() instead of @include_once #746

Open demianturner opened 11 years ago

demianturner commented 11 years ago

The classAvailable method should use file_exists() instead of include_once SGL_BLK_DIR . '/' . $blockClass . '.php';

By using the @ symbol before include_once, all PHP errors are suppressed. If there are parse errors in the block that's being included, or in one of the files that it includes, just a blank page will be shown.

I spent hours trying to figure out why this blank page was being shown.

The old method looks like this:

{{{ function classAvailable($element) { SGL::logMessage("\n===classAvailable() is running===\n"); if ($element) { $blockClass = $this->form->getElementValue('block[name]'); include_once SGL_BLK_DIR . '/' . $blockClass . '.php'; return class_exists($blockClass); } return true; } }}}

You can replace it with:

{{{ function classAvailable($element) { SGL::logMessage("\n===classAvailable() is running===\n"); if ($element) { $blockClass = $this->form->getElementValue('block[name]'); $path = SGL_BLK_DIR . '/' . $blockClass . '.php'; if ( file_exists($path) ){ include_once($path); return class_exists($blockClass); } else{ return false; } } return true; } }}}

I can attach a patch for this, as it would be good to have a fix for it in the stable version of Seagull. (Side note: I think things have changed in 0.6 ... BlockForm is not used any more, because QuickForm is not used in 0.6. I checked the block modules classes in version 0.6, but could not find any corressponding code that checks to see if the class for a block that is being added exists. Anyone have insight on this?)

demianturner commented 11 years ago

[demian] sounds like a good suggestion - patches pls :-)