Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Repository plugin files: Difference between revisions

From MoodleDocs
No edit summary
m (Text replacement - "</code>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Repository plugins}}
This is an overview of the files that are found within [[Repository plugins]].
This is an overview of the files that are found within [[Repository plugins]].
* /repository/myplugin/'''lib.php''' - this contains the core functionality for your plugin. Within it you must define a class:
* /repository/myplugin/'''lib.php''' - this contains the core functionality for your plugin. Within it you must define a class:
<code php>
<syntaxhighlight lang="php">
class repository_myplugin extends repository {
class repository_myplugin extends repository {
   // See [[Repository plugins]] for a list of functions to override in here
   // See [[Repository plugins]] for a list of functions to override in here
}
}
</code>
</syntaxhighlight>
* /repository/myplugin/'''pix/icon.png''' - an icon to display in the file picker (16x16)
* /repository/myplugin/'''pix/icon.png''' - an icon to display in the file picker (16x16)
* /repository/myplugin/'''[[version.php]]''' - contains the current version number of the plugin and other important details ( https://docs.moodle.org/dev/version.php )
* /repository/myplugin/'''[[version.php]]''' - contains the current version number of the plugin and other important details ( https://docs.moodle.org/dev/version.php )
<code php>
<syntaxhighlight lang="php">
defined('MOODLE_INTERNAL') || die();
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012061700; //The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2012061700; //The current plugin version (Date: YYYYMMDDXX)
Line 15: Line 16:
$plugin->cron = 0; // How often to run automatic updates (0 to disable)
$plugin->cron = 0; // How often to run automatic updates (0 to disable)
$plugin->release = 'Human-readable version number';
$plugin->release = 'Human-readable version number';
</code>
</syntaxhighlight>
* /repository/myplugin/'''lang/en/repository_myplugin.php''' - contains the English language strings for display by your plugin. As a minimum, this must include:
* /repository/myplugin/'''lang/en/repository_myplugin.php''' - contains the English language strings for display by your plugin. As a minimum, this must include:
<code php>
<syntaxhighlight lang="php">
defined('MOODLE_INTERNAL') || die();
defined('MOODLE_INTERNAL') || die();
$string['configplugin'] = 'Configuration for my plugin repository';
$string['pluginname'] = 'My plugin repository';
$string['pluginname'] = 'My plugin repository';
$string['configplugin'] = 'Configuration for my plugin repository';
$string['pluginname_help'] = 'A few more details about my repository';
</code>
</syntaxhighlight>
* /repository/myplugin/'''db/access.php''' - defines any user capabilities related to the plugin. A basic access.php file will look like this:
* /repository/myplugin/'''db/access.php''' - defines any user capabilities related to the plugin. A basic access.php file will look like this:
<code php>
<syntaxhighlight lang="php">
defined('MOODLE_INTERNAL') || die();
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
$capabilities = array(
Line 34: Line 36:
     )
     )
);
);
</code>
</syntaxhighlight>


Once the capabilities have been defined, it is good practice to add a language string for them to the '''lang/en/repository_myplugin.php''' file:
Once the capabilities have been defined, it is good practice to add a language string for them to the '''lang/en/repository_myplugin.php''' file:
<code php>
<syntaxhighlight lang="php">
$string['myplugin:view'] = 'View the myplugin repository';
$string['myplugin:view'] = 'View the myplugin repository';
</code>
</syntaxhighlight>


==See also==
==See also==

Latest revision as of 20:22, 14 July 2021

This is an overview of the files that are found within Repository plugins.

  • /repository/myplugin/lib.php - this contains the core functionality for your plugin. Within it you must define a class:
class repository_myplugin extends repository {
  // See [[Repository plugins]] for a list of functions to override in here
}
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2012061700; //The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012061700;  //Requires this Moodle version
$plugin->component = 'repository_myplugin'; //Full name of the plugin (used for diagnostics)
$plugin->cron = 0; // How often to run automatic updates (0 to disable)
$plugin->release = 'Human-readable version number';
  • /repository/myplugin/lang/en/repository_myplugin.php - contains the English language strings for display by your plugin. As a minimum, this must include:
defined('MOODLE_INTERNAL') || die();
$string['configplugin'] = 'Configuration for my plugin repository';
$string['pluginname'] = 'My plugin repository';
$string['pluginname_help'] = 'A few more details about my repository';
  • /repository/myplugin/db/access.php - defines any user capabilities related to the plugin. A basic access.php file will look like this:
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
    'repository/myplugin:view' => array(
        'captype' => 'read',
        'contextlevel' => CONTEXT_MODULE,
        'archetypes' => array(
            'user' => CAP_ALLOW 
        )
    )
);

Once the capabilities have been defined, it is good practice to add a language string for them to the lang/en/repository_myplugin.php file:

$string['myplugin:view'] = 'View the myplugin repository';

See also