<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ABlocks%2FAppendix_B</id>
	<title>Development:Blocks/Appendix B - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ABlocks%2FAppendix_B"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Blocks/Appendix_B&amp;action=history"/>
	<updated>2026-05-06T18:45:35Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Blocks/Appendix_B&amp;diff=10858&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Blocks/Appendix_B&amp;diff=10858&amp;oldid=prev"/>
		<updated>2024-10-21T08:51:02Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:51, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Blocks/Appendix_B&amp;diff=10857&amp;oldid=prev</id>
		<title>1&gt;Mits: ja link</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Blocks/Appendix_B&amp;diff=10857&amp;oldid=prev"/>
		<updated>2009-06-21T15:54:47Z</updated>

		<summary type="html">&lt;p&gt;ja link&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Differences in the Blocks API for Moodle versions prior to 1.5 ==&lt;br /&gt;
&lt;br /&gt;
This Appendix will discuss what changes in the Blocks API were introduced by Moodle 1.5 and what steps developers need to take to update their blocks to be fully compatible with Moodle 1.5. Unfortunately, with these changes backward compatibility is broken; this means that blocks from Moodle 1.4 will never work with 1.5 and vice versa.&lt;br /&gt;
&lt;br /&gt;
=== Class naming conventions changed ===&lt;br /&gt;
In Moodle 1.4, all block classes were required to have a name like &amp;#039;&amp;#039;&amp;#039;CourseBlock_something&amp;#039;&amp;#039;&amp;#039; and the base class from which the derived was &amp;#039;&amp;#039;&amp;#039;MoodleBlock&amp;#039;&amp;#039;&amp;#039;. This has changed in Moodle 1.5, to bring the naming conventions in line with other object-oriented aspects of Moodle (for example there are classes enrolment_base, resource_base etc). The new block classes should instead be named like &amp;#039;&amp;#039;&amp;#039;block_something&amp;#039;&amp;#039;&amp;#039; and derive from &amp;#039;&amp;#039;&amp;#039;block_base&amp;#039;&amp;#039;&amp;#039;. This means that in order to make a block compatible with Moodle 1.5, you need to change the class definition&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
class CourseBlock_online_users extends MoodleBlock { ... }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
to&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
class block_online_users extends block_base { ... }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An exception to the above is the special case where the block is intended to display a list of items instead of arbitrary text; in this case the block class must derive from class &amp;#039;&amp;#039;&amp;#039;block_list&amp;#039;&amp;#039;&amp;#039; instead, like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
class block_admin extends block_list { ... }&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constructor versus &amp;#039;&amp;#039;init()&amp;#039;&amp;#039; ===&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.4, in each block class it was mandatory to define a constructor which accepted a course data record as an argument (the example is from the actual Online Users block):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function CourseBlock_online_users ($course) {&lt;br /&gt;
  $this-&amp;gt;title        = get_string(&amp;#039;blockname&amp;#039;,&amp;#039;block_online_users&amp;#039;);&lt;br /&gt;
  $this-&amp;gt;content_type = BLOCK_TYPE_TEXT;&lt;br /&gt;
  $this-&amp;gt;course       = $course;&lt;br /&gt;
  $this-&amp;gt;version      = 2004052700;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In contrast, Moodle 1.5 does away with the constructor and instead requires you to define an [[Development:Blocks/Appendix_A#init.28.29| init()]] method that takes no arguments:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function init() {&lt;br /&gt;
  $this-&amp;gt;title   = get_string(&amp;#039;blockname&amp;#039;,&amp;#039;block_online_users&amp;#039;);&lt;br /&gt;
  $this-&amp;gt;version = 2004111600;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Of course, this leaves you without access to the $course object, which you might actually need. Since that&amp;#039;s probably going to be needed inside [[Development:Blocks/Appendix_A#get_content.28.29| get_content()]], the way to retrieve it is by using this code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt; &lt;br /&gt;
  $course = get_record(&amp;#039;course&amp;#039;, &amp;#039;id&amp;#039;, $this-&amp;gt;instance-&amp;gt;pageid);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are going to need access to $course from inside other methods in addition to [[Development:Blocks/Appendix_A#get_content.28.29| get_content()]], you might fetch the $course object inside the [[Development:Blocks/Appendix_A#specialization.28.29| specialization()]] method and save it as a class variable for later use, in order to avoid executing the same query multiple times:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function specialization() {&lt;br /&gt;
  $this-&amp;gt;course = get_record(&amp;#039;course&amp;#039;, &amp;#039;id&amp;#039;, $this-&amp;gt;instance-&amp;gt;pageid);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Blocks with configuration ===&lt;br /&gt;
&lt;br /&gt;
In Moodle 1.4, blocks could only have what are now (in Moodle 1.5) called &amp;quot;global configuration&amp;quot; options, to differentiate from the new &amp;quot;instance configuration&amp;quot; options. If your block has support for configuration, you will need to take these steps:&lt;br /&gt;
&lt;br /&gt;
# Rename your &amp;#039;&amp;#039;&amp;#039;config.html&amp;#039;&amp;#039;&amp;#039; file to &amp;#039;&amp;#039;&amp;#039;config_global.html&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
# Edit the newly renamed file and completely remove the &amp;lt;form&amp;gt; tag (Moodle now wraps your configuration in a form automatically).&lt;br /&gt;
# If you are using any HTML &amp;lt;input&amp;gt; tags other than those that directly affect your configuration (for example, &amp;quot;sesskey&amp;quot;), REMOVE those too (Moodle will add them automatically as required).&lt;br /&gt;
# If you have overridden &amp;#039;&amp;#039;&amp;#039;print_config&amp;#039;&amp;#039;&amp;#039;, rename your method to [[Development:Blocks/Appendix_A#config_print.28.29|config_print()]].&lt;br /&gt;
# If you have overridden &amp;#039;&amp;#039;&amp;#039;handle_config&amp;#039;&amp;#039;&amp;#039;, rename your method to [[Development:Blocks/Appendix_A#config_save.28.29|config_save()]].&lt;br /&gt;
&lt;br /&gt;
=== Blocks with customized applicable formats ===&lt;br /&gt;
&lt;br /&gt;
The correct way to specify the formats you want to allow or disallow your block to exist has been reworked for Moodle 1.5 to take account of the fact that blocks are no longer restricted to just courses. To have a block retain its intended behavior, you must change these format names (array keys in the return value of [[Development:Blocks/Appendix_A#applicable_formats.28.29| applicable_formats()]] if they are used in your block:&lt;br /&gt;
&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;social&amp;#039;&amp;#039;&amp;#039; should become &amp;#039;&amp;#039;&amp;#039;course-view-social&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;topics&amp;#039;&amp;#039;&amp;#039; should become &amp;#039;&amp;#039;&amp;#039;course-view-topics&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;weeks&amp;#039;&amp;#039;&amp;#039; should become &amp;#039;&amp;#039;&amp;#039;course-view-weeks&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
You should also keep in mind that there is now the possibility of blocks being displayed in other pages too, like the introductory page that users see when they enter an activity module. You might therefore need to make the specification for applicable formats more restrictive to keep your block out of pages it is not supposed to be shown in. Also, there are subtle changes to the way that the final decision to allow or disallow a block is made. For the technical details refer to the definition of [[Development:Blocks/Appendix_A#applicable_formats.28.29| applicable_formats()]], and for a more extended example read [[Development:Blocks#Authorized_Personnel_Only|Authorized Personnel Only]], the section dedicated to this subject.&lt;br /&gt;
&lt;br /&gt;
That&amp;#039;s everything; your block will now be ready for use in Moodle 1.5!&lt;br /&gt;
&lt;br /&gt;
[[Category:Developer|Blocks]]&lt;br /&gt;
[[Category:Tutorial]]&lt;br /&gt;
&lt;br /&gt;
[[es:Desarrollo de bloques]]&lt;br /&gt;
[[ja:開発:ブロック/付録B]]&lt;/div&gt;</summary>
		<author><name>1&gt;Mits</name></author>
	</entry>
</feed>