What makes a block incompatible?

What makes a block incompatible?

by Steven Williams -
Number of replies: 4
I have been working on a few custom blocks for my institution, for easy-to-add links to various library resources in the form of blocks that instructors can add to a course.

I'm currently experiencing a very strange error. I developed a simple block a few weeks ago that contains an image and link to an external website; this has been deployed on our production server successfully, and is working without any issues. I began work today on a new custom block and used the block I developed before as a template -- however, for some reason the new block I have created breaks Moodle, resulting in an unloadable Notifications page, and preventing any blocks from being added to any course. After removing the new block from my blocks directory, I receive the notification on my Blocks management page that my new block is incompatible and can then delete it -- but as long as the block is present, the Blocks management page won't load at all. (This is in a local, Macintosh-hosted installation of Moodle 1.9.4). However, the block did install successfully in a Windows-based local installation of Moodle 1.9.3 on a colleague's computer.

As part of troubleshooting, I rewrote my new block to be identical to the original custom block I created, with the only differences being the block name in the "class block_name extends block_base {" field, the title in the "$this->title = 'Title';" field, and the version number. However, the new block will not work, even with every line of code besides the three above being completely identical to the first block I developed.

What might it be about my second block that is preventing it from being loaded into my Moodle installation? I have found a number of forum posts where users report similar issues to what I'm experiencing in terms of a block being incompatible, but I'm struggling to find any documentation that is developer-oriented to prevent and troubleshoot custom blocks which won't install correctly. Any guidance or suggestions are more than welcome.
Average of ratings: -
In reply to Steven Williams

Re: What makes a block incompatible?

by M. N. -
I would recommend checking your PHP error log if you haven't already as you may have a syntax error in your block that is causing execution to stop. You can turn on debug messages from Site Administration > Server > Debugging. See the debugging docs for more info.
Average of ratings: Useful (1)
In reply to Steven Williams

Re: What makes a block incompatible?

by Anthony Borrow -
Picture of Core developers Picture of Plugin developers Picture of Testers
Steven - Take a look at /lib/blocklib.php for a function called block_is_compatible(). It has to do with the comment in that function:

// If you find MoodleBlock (appearing in the class declaration) it's not compatible

so remove MoodleBlock and you should find yourself a compatible block.

Peace - Anthony
In reply to Steven Williams

Re: What makes a block incompatible?

by Dan Poltawski -
Its sounds like you had a php error with your new block which caused the blank pages, like MN says, check the error log. Regarding the 'incompatible' error, its probably a bad error message - because the file does not exist any longer.

I should probably create a bug about that as its annoyed me before. Actually, having just re-read block_is_compatible(), there should be a bug to take that function out the back and shoot it it. evil
In reply to Steven Williams

Re: What makes a block incompatible?

by Steven Williams -
Thanks for the suggestions -- I was able to use Moodle's debugging features in order to discover and resolve some problems in both my newer and older custom blocks.