Create a NEWMODULE moodle 2.0

Create a NEWMODULE moodle 2.0

by dirty slit -
Number of replies: 17
Please I would like some information on how to do this.
Average of ratings: -
In reply to dirty slit

Re: Create a NEWMODULE moodle 2.0

by yokivo kade -
Download Newmodule file in compressed form un compress it in a folder of ur choice and follow the instruction given in ReadMe.txt file.
In reply to yokivo kade

Re: Create a NEWMODULE moodle 2.0

by dirty slit -
Thanks I downloaded the HEAD version of this file from this documentation page.

http://docs.moodle.org/en/Development:NEWMODULE_Documentation


Would this be the appropriate NEWMODULE.zip to begin developing modules for moodle 2.0?
In reply to dirty slit

Re: Create a NEWMODULE moodle 2.0

by yokivo kade -
Yes sure!
follow the instruction in readme file. and a module with basic working will be ready.

add ur contents in specific portion of mod_form.php shown by using comments.
In reply to yokivo kade

Re: Create a NEWMODULE moodle 2.0

by yokivo kade -
sorry i mistakenly wrote mod_form.php. use view.php instead of mod_form.php
cheers!
In reply to yokivo kade

Re: Create a NEWMODULE moodle 2.0

by Joe Cape -
Picture of Plugin developers
Hi,
I have gone through these instructions to set up a new module for Moodle 2.0 after downloading the following: http://download.moodle.org/plugins/mod/NEWMODULE.zip .
  1. Choose a name for your module. Take care: no capital letter and no numbers in the name. In this example it will be choosen: "widget".
  2. Use a good text editor to perform a multi-file find/replace to change all occurrences of "newmodule" in each file with the name of your own module.
  3. Change the name of the folder containing your newly-created module to "widget".
  4. Change the name of file "widget/lang/en_utf8/newmodule.php" to "widget.php".
  5. Put your newly-created widget folder in moodle/mod/.
  6. Visit the Moodle "Notifications" page (in the Moodle->Site Administration block) to trigger installation of your module.
  7. Follow the instructions on the screen.

I will reproduce here the error that I get. At the top of the page I see the following:

Invalid get_string() identifier: 'configtitle' or component 'theme_universite'
  • line 6074 of /lib/moodlelib.php: call to debugging()
  • line 6629 of /lib/moodlelib.php: call to core_string_manager->get_string()
  • line 6 of /theme/universite/settings.php: call to get_string()
  • line 29 of /admin/settings/appearance.php: call to include()
  • line 5571 of /lib/adminlib.php: call to require()
  • line 2674 of /lib/navigationlib.php: call to admin_get_root()
  • line 2584 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
  • line 583 of /lib/pagelib.php: call to settings_navigation->initialise()
  • line 599 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
  • line 132 of /blocks/settings/block_settings.php: call to moodle_page->__get()
  • line 279 of /blocks/moodleblock.class.php: call to block_settings->get_content()
  • line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
  • line 895 of /lib/blocklib.php: call to block_base->get_content_for_output()
  • line 947 of /lib/blocklib.php: call to block_manager->create_block_contents()
  • line 342 of /lib/blocklib.php: call to block_manager->ensure_content_created()
  • line 6 of /theme/anomaly/layout/general.php: call to block_manager->region_has_content()
  • line 647 of /lib/outputrenderers.php: call to include()
  • line 605 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
  • line 2106 of /lib/outputrenderers.php: call to core_renderer->header()
  • line ? of unknownfile: call to core_renderer->fatal_error()
  • line 1200 of /lib/setuplib.php: call to call_user_func_array()
  • line ? of unknownfile: call to bootstrap_renderer->__call()
  • line 320 of /lib/setuplib.php: call to bootstrap_renderer->fatal_error()
  • line 984 of /lib/upgradelib.php: call to default_exception_handler()
  • line 1406 of /lib/upgradelib.php: call to upgrade_handle_exception()
  • line 290 of /admin/index.php: call to upgrade_noncore()
Invalid get_string() identifier: 'pluginname' or component 'auth_lgde_hal'
  • line 6074 of /lib/moodlelib.php: call to debugging()
  • line 6629 of /lib/moodlelib.php: call to core_string_manager->get_string()
  • line 75 of /admin/settings/plugins.php: call to get_string()
  • line 5573 of /lib/adminlib.php: call to require()
  • line 2674 of /lib/navigationlib.php: call to admin_get_root()
  • line 2584 of /lib/navigationlib.php: call to settings_navigation->load_administration_settings()
  • line 583 of /lib/pagelib.php: call to settings_navigation->initialise()
  • line 599 of /lib/pagelib.php: call to moodle_page->magic_get_settingsnav()
  • line 132 of /blocks/settings/block_settings.php: call to moodle_page->__get()
  • line 279 of /blocks/moodleblock.class.php: call to block_settings->get_content()
  • line 232 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
  • line 895 of /lib/blocklib.php: call to block_base->get_content_for_output()
  • line 947 of /lib/blocklib.php: call to block_manager->create_block_contents()
  • line 342 of /lib/blocklib.php: call to block_manager->ensure_content_created()
  • line 6 of /theme/anomaly/layout/general.php: call to block_manager->region_has_content()
  • line 647 of /lib/outputrenderers.php: call to include()
  • line 605 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
  • line 2106 of /lib/outputrenderers.php: call to core_renderer->header()
  • line ? of unknownfile: call to core_renderer->fatal_error()
  • line 1200 of /lib/setuplib.php: call to call_user_func_array()
  • line ? of unknownfile: call to bootstrap_renderer->__call()
  • line 320 of /lib/setuplib.php: call to bootstrap_renderer->fatal_error()
  • line 984 of /lib/upgradelib.php: call to default_exception_handler()
  • line 1406 of /lib/upgradelib.php: call to upgrade_handle_exception()
  • line 290 of /admin/index.php: call to upgrade_noncore()

And within the body of the page, I see this:

Plugin "theme_RSMS_Home" is defective or outdated, can not continue, sorry.

More information about this error

Debug info: Invalid plugin directory name.
Stack trace:
  • line 280 of /lib/upgradelib.php: plugin_defective_exception thrown
  • line 1403 of /lib/upgradelib.php: call to upgrade_plugins()
  • line 290 of /admin/index.php: call to upgrade_noncore()

 

 

----------------------------------------------------------------

Is there a fix for this or another blank template available to help develop modules for Moodle 2.0? I have tried looking for guides on the API that should be used and the conventions on how to structure a Moodle 2.0 module but the closest I can find is this 'Introduction to Moodle Programming' ( http://dev.moodle.org/login/index.php ) which teaches you how to design a block for Moodle 1.9, which is two steps removed from what I'm looking for.

The other suggestion I've heard is to examine how the label module works as it is the simplest module so I may do that. Any suggestions on the best place to start building a module (I'm a decent php programmer, I have worked with Moodle 2.0 for 4 months and I have looked at the code behind it during that time) are welcome.

In reply to Joe Cape

Re: Create a NEWMODULE moodle 2.0

by Matt Gibson -

Looks like you have a few missing or inaccessible language strings. I'm working with newmodule right now and have not had this problem (although I had a few others).

What are 'theme_universite' and 'auth_lgde_hal'? Moodle often uses directory names as route into plugins, so it's worth checking you have those exactly the same as the plugin names for these.

It's also possible that these errors are from something else - have you tried your newmodule on a completely clean 2.0 install?

Average of ratings: Useful (1)
In reply to Matt Gibson

Re: Create a NEWMODULE moodle 2.0

by Joe Cape -
Picture of Plugin developers

I will try installing on a clean set up to see whether something else has caused the problem.

Meanwhile, I am trying to follow through the same instructions (1..7) for, eg., creating a clone of the label and page resources. This is something that I've had more success with - I've got the new modules (like mod/pageclone) to install. However, something causes an exit when the resource is viewed from the course page. I've identified that the exit happens somewhere in the set url function (line 61 of mod\clonepage\view.php).

The code is read up to here.

$clonepage->set_url('/mod/clonepage/view.php', array('id' => $cm->id));      //line 61

The page has crashed by here.

I was just trying to do this to have something to work with to try and flesh out a new module that suites my needs.

I'm not sure about missing language strings; I must be downloading the same copy of the module as everyone else is able to download so unless there is a general problem with missing strings, I don't see why that would be a problem specific to me. As you say , it is possible that there is a conflict with something I have already installed.

In reply to Joe Cape

Re: Create a NEWMODULE moodle 2.0

by Upma Gupta -

I have install it. But facing problems when trying to add this activity to a course.

error is: Coding error detected, it must be fixed by a programmer: MFORMS: Coding error, text formats are handled only by new editor element.

In reply to Upma Gupta

Re: Create a NEWMODULE moodle 2.0

by Jamie Pratt -

You probably need to switch to using the editor instead of the htmleditor element. I believe htmleditor may be deprecated in 2.1 editor handles files properly.

Average of ratings: Useful (1)
In reply to Jamie Pratt

Re: Create a NEWMODULE moodle 2.0

by Upma Gupta -

Thanks for guide me. Now i am able to see the form to insert activity to course. But when I click on save and return to course button error comes: insert_record() not available anymore.

Other problem is that It's viewing modulename in brackets instead of my module name.

In reply to Upma Gupta

Re: Create a NEWMODULE moodle 2.0

by H Bomb -

The form uses common buttons (last line of code--add_action_buttons()). Unless you override those buttons the form processing and insert_record() should be performed by core moodle code. Since you're getting and error, it is likely on your side: I'd start by checking to ensure my database is connected and the table(s) exist.

An example of a basic mod_form.php file is below. See the code comments for what each line does. Your mod_form.php file should look similar to it.

require_once($CFG->dirroot.'/course/moodleform_mod.php');

class mod_avrecorder_mod_form extends moodleform_mod {

    function definition() {

        global $COURSE, $CFG;
        $mform =& $this->_form;


        // Adding the "general" fieldset, where all the common settings are shown
        $mform->addElement('header', 'general', get_string('general', 'form'));

        // Adding the standard "name" field
        $mform->addElement('text', 'name', get_string('avrecordername', 'avrecorder'), array('size'=>'64'));
        if (!empty($CFG->formatstringstriptags)) {
            $mform->setType('name', PARAM_TEXT);
        } else {
            $mform->setType('name', PARAM_CLEANHTML);
        }
        $mform->addRule('name', null, 'required', null, 'client');
        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');

        // Adding the required "intro" field to hold the description of the instance
        $this->add_intro_editor(true, get_string('description', 'avrecorder'));

        // add standard elements, common to all modules
        $this->standard_coursemodule_elements();


        // add standard buttons, common to all modules
        $this->add_action_buttons();

    }
}

 

modulename in brackets has to do with the language strings module > lang > en > modulename.php file should host all your strings. Be sure to set $string['modulename'] = "yourmodulename" and $string['pluginname'] = "yourmodulename".

Also, clear or disable moodle's cache and your browser's cache during development to ensure you always see your changes.

Average of ratings: Useful (1)
In reply to H Bomb

Re: Create a NEWMODULE moodle 2.0

by Johnny Zephyr -

 Hi

 I'm looking to create a plugin that will retrieve data from the database per user from a custom table. I have used the internal $db but am finding that in order to get a result i have to 'purge all caches' each time. I'm having the caching problem as well, How would you disable all caches in moodle or atleast just the one for the newmodule?

 My plugin is similar to the 'label' plugin except the name is dynamic; it changes depending on the results retrieved from my custom table. So users will log in and view a course and that 'label' will change depending on who they are... so user 1 may see 'xyz' and user 2 may see '123'. Just to clarify, this all happens on the course 'view' page.

 I'm at the stage where once the 'label' has been set, only a 'purge all caches' will query the db again and update 'labels' - this isn't fit for purpose as learners can't do this.

 How do we go about disabling the cache for this one plugin if possible?

 I've disabled every other cache in moodle that I know of from the caching plugin. I've disabled browser caches etc... but the only thing that works is that overall purge. I'm upgrading from 1.9 to 2.7 so alot has changed. I don't want to 'inject' code in the middle of a format as i wanted to try the plugin/newmodule out.

 Any help is welcomed and much appreciated.

 Thanks

In reply to Johnny Zephyr

Re: Create a NEWMODULE moodle 2.0

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators
Can you please elaborate on how exactly you are displaying the content at the course view page - or even better share your work-in-progress code/repository so we can see the things in context.
In reply to David Mudrák

Re: Create a NEWMODULE moodle 2.0

by Johnny Zephyr -

hi david

this is sorted now.

I was using get_coursemodule_info where i should have been using cm_info_view. get_coursemodule_info caches data whereas cm_info_view is live.

Thanks

In reply to Matt Gibson

Re: Create a NEWMODULE moodle 2.0

by Tobias Sopu -

Hi Matt,

Thanks for the tip, when you say "complete clean noodle 2.0" what do you mean?

I'm trying to write one for Facebook comment box and one of the activities,

please advice.

In reply to Joe Cape

Re: Create a NEWMODULE moodle 2.0

by Anne Krijger -

As I mentioned in another post yesterday, I do not get the impression htat the NEWMODULE.zip contains a 2.x example, but still the latest 1.9 example of creating e new Moodle module.

In this account of converting to 2.0 module; http://docs.moodle.org/dev/Migrating_contrib_code_to_2.0/Experience_of_converting_a_module_to_Moodle_2

Sam mentions that the language directory no longer is called 'en_utf8' but just 'en'. I guess some of your issues may arise there.

BTW; If at all possible, set up debugging for PHP when making changes.

It takes a little bit of effort but can save you heaps of time and frustration.

Anne.