Blocks developers: Oops, I did it again!

Blocks developers: Oops, I did it again!

by John Papaioannou -
Number of replies: 0
To anyone who is using blocks:

I 've just changed the correct way to define applicable formats, as they are returned from the applicable_formats() overridden method of block classes.

The format of 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 e.g. of any quiz view page is "mod-quiz-view". Exceptions:

  1. The format of the site index is "site-index" (although blocks that define "site" => true will work fine, see the matching rules below).
  2. The format of 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

This is designed so that the applicability of blocks can now be very easily controlled even in pages that we know simply nothing about (putting in foundations for the future).

Although this works fine for me, please test it a bit to see if the behavior is unchanged in your installations.

Thanks! smile
Jon
Average of ratings: -