mudrd8mz / moodle-tool_pluginskel

Generator of Moodle plugins skeletons
https://moodle.org/plugins/tool_pluginskel
Other
51 stars 46 forks source link

Files mandatory for a plugin type #33

Closed alexandru-elisei closed 8 years ago

alexandru-elisei commented 8 years ago

A plugin is expected to have a set of required files specific to that plugin type. For example, an activity module is required to have the files lib.php, mod_form.php, index.php and view.php (and db/install.xml, but that is better generated by the XMLDB editor).

These files should be generated implicitely based on the plugin type, and the user shouldn't have to explicitely specify them in the recipe file.

For this purpose I propose that the function manager::prepare_file_skeletons() will call two separate functions:

For now, I propose that prepare_plugin_specific_skeletons() will add the plugin-specific files in series of if statements based on the plugin type:

public function prepare_plugin_specific_skeletons() {

    $plugintype = $this->recipe['component_type'];

    if ($plugintype === 'mod') {
        $this->prepare_file_skeleton('mod_form.php', 'php_internal_file', 'mod_form');
        $this->prepare_file_skeleton('view.php', 'php_web_file', 'view');
        ...
    }

    if ($plugintype === 'block') {
         $this->prepare_file_skeleton($this->recipe['component'].'.php', 'php_internal_file', 'block');
         ...
    }
    ...
}
alexandru-elisei commented 8 years ago

It is worth noting that as we add support for generating more and more plugin types the above function can get unmanageably long. If we find that that is the case, one solution could be to have separate functions that add the files required for each plugin type:

public function prepare_plugin_specific_skeletons() {

    $plugintype = $this->recipe['component_type'];

     switch ($plugintype) {
         case: 'mod':
              $this->prepare_mod_file_skeletons();
              break;
         case: 'block':
              $this->prepare_block_file_skeletons();
              break;
         ...
         default:
               throw new exception('Unsupported plugin type: '.$plugintype);
     }
}

EDIT: I actually like this suggestion a lot more than the first one.

alexandru-elisei commented 8 years ago

Closing the issue, solved by pull request #45