Now blocks_have_content() caches instantiated block objects inside $pageblocks
and blocks_print_blocks() uses them if available. This behaviour now matches
the documentation: blocks instances are created only once, get_content()
may be invoked several times.
A better fix would be to cache the _output_ of the block (the ->content
property) but it may bite us if any block is counting on being called twice.
Discussion at: http://moodle.org/mod/forum/discuss.php?d=45867
and from blocks admin page and their instances haven't been deleted.
We should build some sort of check to do all the house-cleaning of "orphaned"
blocks, perhaps each time we arrive to the blocks admin page.
Per-block access controls for creating and editing block instances. Defaults
behave the same as before, and the framework has final say as before.
See relevant discussion at http://moodle.org/mod/forum/discuss.php?d=36444
Other minor changes: Converted "continue" to "break" inside switch statements
(more to the point, although equivalent), change erroneous (but harmless)
"return false" to "break" on failed addition of block instance, removed some
inline comments from block_base (they were duplicated in PHPdoc)
call_user_func is about 3 times faster than eval(). Which is no surpise. ;-)
Faster block_load_class() by checking if the block class is already present
instead of relying on require_once() and include_once() which have include
paths and other nasties to take into account.
Implementing Dan Marsden's great idea for additional hooks when block
instances are deleted (bug 3446). Going a step further and adding hooks
for when block instances are created.
* Block authors no longer need to set $this->content_type
* If you want to make a "list" block, just derive from block_list
instead of block_base
* All switch() statements gone from library code
* Overloaded method is_empty() added to block classes for convenience
display in a page. Previously it returned the FIRST match; now it returns
the BEST match.
This allows things like
array('all' => true, 'mod' => false, 'mod-quiz' => true)
to work correctly regardless of the order the array elements appear in.
Also, encapsulated the check into a function (it has definitely become
non-trivial).
The format for each page is now the same as the id attribute of the
BODY tag, which in turn is a simple function of the script's relative path:
The format for e.g. a quiz view page is "mod-quiz-view". The format for the
site index is "site-index". Exception: the format for courses is not just
"course-view", but "course-view-weeks" etc.
Obviously the applicable_formats() override for each block should now take
this into account. The matching rules now are:
* You can specify the full format, e.g. "mod-quiz-view" => true
will allow the block to be added in quizzes
* Prefixes match the full page format, e.g. "mod" matches ALL activities
* You can use "*" as a wildcard, e.g. "mod-*-view" matches just the view.php
page of all activities
* These rules interoperate, thus "mod-*" is the same as "mod"
* "all" remains as a catch-all situation
The new constant is PAGE_COURSE_VIEW, and it's more streamlined with the
new CSS-related ids for 1.5. There are great possibilities for the future
here, so we 're getting ready.
On the other hand, this has to be the ugliest hack I 've ever inflicted
on any program (look at pagelib.php). Thankfully it will only stay for just
a little while.
Make it more difficult for instances with invalid blockid to be added to
mdl_block_instance. This could result in warnings, although nothing more
serious than that.
Credits to Eloy and especially Dan Marsden for reporting and providing info.
* When configuring a block instance, "Turn editing off" button is not
shown anymore.
* When configuring a block instance, the breadcrumbs are now better,
providing a link to the course page. This could be done in a much
better way if we had a comprehensive template system but it will
suffice for now.
I hope this time I got everything changed to the new Page interface! I 'm
really sorry for messing up and breaking new installations... :(
Also moved the only two functions of the API outside the page_base class.