Repository method instance_config_form has to be static in Moodle 2.3

Repository method instance_config_form has to be static in Moodle 2.3

Tim Williams -
回帖数:6
Plugin developers的头像
I'm testing a repository module on Moodle 2.3 and I've hit a problem. I note that it is now necessary for the method instance_config_form($mform) in a repository module to be static, not doing so gives the following error:

PHP Fatal error: Cannot make static method repository::instance_config_form() non static in class repository_helix_media_lib in /home/httpd/mdl23.autotrain.org/html/repository/helix_media_lib/lib.php on line 292

However, changing this method to static then breaks the plugin in earlier versions of Moodle, with the following error:

Cannot make non static method repository::instance_config_form() static in class repository_helix_media_lib in /home/httpd/mdl2.autotrain.org/html/repository/helix_media_lib/lib.php on line 292

Is there any way that I can write this so that the repository works in all versions from 2.0 to 2.3, or am I now going to have to produce separate versions for Moodle 2.0 to 2.3 and 2.3 in order to account for this. Everything else works in all versions so I really don't want to have to split the code base for something as trivial as this.

I suspect that this related to issue http://tracker.moodle.org/browse/MDL-32573 .
回复Tim Williams

Re: Repository method instance_config_form has to be static in Moodle 2.3

Dan Poltawski -
Hi Tim,

Unfortunately I think you are going to have to make two separate versions.

We needed to make these changes in the API in order to make Moodle compatible with PHP 5.4. Really those methods should have been static from the start 伤心
回复Dan Poltawski

Re: Repository method instance_config_form has to be static in Moodle 2.3

Dan Poltawski -
PS. MDL-32600 is the bug for us documenting these API changes. I'm afraid we are quite behind on that.
回复Dan Poltawski

Re: Repository method instance_config_form has to be static in Moodle 2.3

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像

I thought that API changes like this should be documented in a file like message/upgrade.txt in the code ... and that integrators should not accept patches with API changes like this if they fail to document the change in upgrade.txt.

(Those changes should also be documented in the release notes, but that can mostly be done briefly on the wiki, with a link to the details in the upgrade.txt file.)

回复Tim Hunt

Re: Repository method instance_config_form has to be static in Moodle 2.3

Dan Poltawski -
Yes, that is why I said we were behind on that. upgrade.txt has been added just a few hours ago.

I also noted that it needed to be done on the original bug (MDL-32573) when I realised and created a new issue for it. We don't get everything right first time, all the time. But hopefully with your help we can get it right eventually. 微笑
回复Dan Poltawski

Re: Repository method instance_config_form has to be static in Moodle 2.3

Tim Williams -
Plugin developers的头像
In these circumstances I would argue that you should have used new method names for the static methods and then have the old non-static methods pass through to the new static version in Add-ons which have been converted for Moodle 2.3. This would have allowed the addons to continue to function in all versions without breaking API compatibility with older releases. Was this ever considered?

The 6 month release cycle has already increased my testing work load significantly and this change is going add to this problem.
回复Dan Poltawski

Re: Repository method instance_config_form has to be static in Moodle 2.3

Tim Williams -
Plugin developers的头像
OK, I think I've worked out a way to get around this problem without splitting my code base and increasing my work load. I've got the same issue with the "type_config_form" method in my Course File Area repository. The solution is to use a simple additional class which provides the correct mapping of the methods for the version of Moodle in use:

In lib.php, I have the following:

if ($CFG->version >= 2012061800)
require_once($CFG->dirroot."/repository/coursefilearea/lib23.php");
else
require_once($CFG->dirroot."/repository/coursefilearea/lib20.php");

class repository_coursefilearea extends repository_coursefilearea_abs
{

public static function type_config_form_real($mform)
{
/**Method body**/
}

/**Rest of class methods here**/

}

Then I have lib20.php for Moodle 2.0, 2.1 and 2.2, which looks like this:

class repository_coursefilearea_abs extends repository
{
public function type_config_form($mform)
{
repository_coursefilearea::type_config_form_real($mform);
}
}

and lib23.php for Moodle 2.3, which looks like this:

class repository_coursefilearea_abs extends repository
{
public static function type_config_form($mform)
{
repository_coursefilearea::type_config_form_real($mform);
}
}