3

I am developing a module for Moodle. I've achieve to install and instantiate it in a course. The problem is that, in "edit mode" enabled, moodle me out the following message:

The module mymodule does not define the standard capability mod/mymodule:addinstance

    line 3451 of \course\lib.php: call to debugging()
    line 1899 of \course\lib.php: call to course_allowed_module()
    line 1767 of \course\lib.php: call to get_module_metadata()
    line 682 of \course\format\renderer.php: call to print_section_add_menus()
    line 49 of \course\format\weeks\format.php: call to format_section_renderer_base->print_multiple_section_page()
    line 276 of \course\view.php: call to require()

In /mod/mymodule/db/access.php file I have the following code:

defined('MOODLE_INTERNAL') || die();

$capabilities = array(
    'mod/mymodule:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'guest' => CAP_ALLOW,
            'student' => CAP_ALLOW,
            'teacher' => CAP_ALLOW,
            'editingteacher' => CAP_ALLOW,
            'admin' => CAP_ALLOW
        )
    ),

    'mod/mymodule:submit' => array(
        'riskbitmask' => RISK_SPAM,
        'captype' => 'write',
        'contextlevel' => CONTEXT_MODULE,
        'legacy' => array(
            'student' => CAP_ALLOW
        )
    ),
);

I am a beginner in module development for Moodle. I have read the following documentation:

But I have not clarified anything.

EDITED 2013-04-28

I have added this code to my access.php file ($capabilities array):

'mod/mymodule:myaddinstance' => array(
                'captype' => 'write',
                'contextlevel' => CONTEXT_SYSTEM,
                'archetypes' => array(
                        'user' => CAP_ALLOW
                ),

                'clonepermissionsfrom' => 'moodle/my:manageblocks'
        ),

        'mod/mymodule:addinstance' => array(
                'riskbitmask' => RISK_SPAM | RISK_XSS,

                'captype' => 'write',
                'contextlevel' => CONTEXT_MODULE,
                'archetypes' => array(
                        'editingteacher' => CAP_ALLOW,
                        'manager' => CAP_ALLOW
                ),

                'clonepermissionsfrom' => 'moodle/site:manageblocks'
        ),

But it doesn't works.

Lobo
  • 4,001
  • 8
  • 37
  • 67
  • None of the lines in your error message mention `access.php`. Perhaps the problem is in `view.php`? – ASGM Apr 27 '13 at 18:02
  • I do not think the problem is in file view.php, because I get this message in the list of course activities, not in the view of mymodule. When I enter in mymodule view (view.php) do not visualize any problems. – Lobo Apr 27 '13 at 18:30
  • Are you using moodle 2.4 or above? – ASGM Apr 28 '13 at 08:53
  • Sorry. The version is 2.4.3+ (Build: 20130328) – Lobo Apr 28 '13 at 09:03
  • Then I think I've found the problem; see my answer. – ASGM Apr 28 '13 at 09:05

1 Answers1

4

At first it seemed like a strange error message, since it mentions mod/mymodule:addinstance but you don't have that in your code. But on closer inspection, that seems to be the problem - moodle expects you to define addinstance but you don't!

This is apparently a new behavior from 2.4 onwards: http://docs.moodle.org/dev/Blocks#db.2Faccess.php

The solution seems to be to add addinstance (and possibly myaddinstance, depending on your settings and implementation) to your $capabilities array.

ASGM
  • 11,051
  • 1
  • 32
  • 53
  • Reading your solution,I add this to my access.php: 'mod/mymodule:myaddinstance' => array( 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => array( 'user' => CAP_ALLOW ), 'clonepermissionsfrom' => 'moodle/my:manageblocks' ), 'mod/mymodule:addinstance' => array( 'riskbitmask' => RISK_SPAM | RISK_XSS, 'captype' => 'write', 'contextlevel' => CONTEXT_MODULE, 'archetypes' => array( 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW ), 'clonepermissionsfrom' => 'moodle/site:manageblocks' ), – Lobo Apr 28 '13 at 09:37
  • 2
    Ok, It works!. The problem was that, after updating the access.php file, I did not change the version number in the file version.php to update the module and new capabilities are included. http://docs.moodle.org/dev/Modules#access.php – Lobo Apr 28 '13 at 10:41