Displaying a line of text on form.

Displaying a line of text on form.

by Padmahasa B N -
Number of replies: 8

Hello everyone,

I referred this link to display a para of text on a form. But the below code could only output [{test}] (Replace flower brackets with big brackets. I tried typing big brackets but this editor is considering it as a link and showing the link.). Can you please show me what's wrong I'm doing here?

In the below mentioned path I've two strings.

\www\moodle\lang\en\moodle.php

$string['test'] = 'This is just a line of text to test printing on a moodle form

TEST TEST TEST TEST';

$string['testlbl'] = 'Test';

In this path I'm using this text by the help of "get_string" function in this path "\www\moodle\user\editadvanced_form.php".

$mform->addElement ( 'static', 'testlbl', get_string ( 'testlbl' ), get_string('test', 'moodle') ); 

Thank you.

Average of ratings: -
In reply to Padmahasa B N

Re: Displaying a line of text on form.

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You need to purge your site caches (or bump your plugin version number, which does that automatically) before Moodle picks up any new (or modified) language strings.

But, please don't add language strings to core files - add them to a custom plugin instead (or else you're going to have problems when you next try to upgrade).


In reply to Davo Smith

Re: Displaying a line of text on form.

by Padmahasa B N -
Hello Davo Smith,

Thank you for your quick reply.

Unfortunately the previous developer has used \moodle\lang\en\moodle.php file for storing strings. And as you can see in my question, the strings called inside editadvanced_form.php which has been created inside /moodle/user which means its not a custom plugin with separate version.php file.

So now the only version.php file I had to edit is of core moodle's file.

How can I change moodle's version.php file, without affecting any future upgrade process? Or is there any alternative way to achieve this?

Thank you.

In reply to Padmahasa B N

Re: Displaying a line of text on form.

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

From the sound of it, what the previous developer has done has already affected any future upgrade process and those changes are likely to be lost in such an upgrade. The general advice is NOT to make changes to core files in that way.

Your options would appear to be to log those change somewhere so that when you do upgrade you can replace the edits made to core, or (recommended) take this opportunity to split out the previous work and turn it into a proper plugin that can be managed separately as part of any upgrade process as with any other plugin.

In reply to Richard Oelmann

Re: Displaying a line of text on form.

by Padmahasa B N -

Hi Richard Oelmann,

It turns out editadvanced_form.php is also the core moodle file and not the one created by developer. So if I want to customize the user's edit and add new user page itself, which lang file should I use?

In this case I need to customize what moodle already provides.

Besides purging the cache as suggested by Davo Smith which reflected the changes, is there any coding way of doing this?

Thank you.

In reply to Padmahasa B N

Re: Displaying a line of text on form.

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Whilst the ideal would be to bump your custom plugin's version.php, if you don't have a custom plugin, you are better off just purging the system caches through the Site admin > developer settings page.

Certainly don't mess around with the main Moodle version.php file!

In reply to Davo Smith

Re: Displaying a line of text on form.

by Padmahasa B N -

Solved!!!

Thank you Davo Smith, purging the cache in "Site admin -> Development -> Purge all caches" reflected all the changes that I had made to the code.

But in my case I want to customize user's page itself, such as "edit page" and "add new user" page etc by showing some of the fields in edit page and hiding some in add new user page like that. How can I do customization on moodle provided plugins? Should I recreate the whole "user plugin" and use that?

That page also suggests that there is no danger in doing this action. Then why it has not mentioned in the documentation that, to reflect changes made to code, one has to purge all caches?

In reply to Padmahasa B N

Re: Displaying a line of text on form.

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Well, it is mentioned in several places in the developer documentation that you need to purge caches (or bump version numbers) to see changes to language strings, etc.

If you feel there are extra places in the docs where this information should be added, then feel free to edit those pages (the docs are a wiki and anyone can edit them).


Average of ratings: Useful (1)
In reply to Davo Smith

Re: Displaying a line of text on form.

by Padmahasa B N -

Hey Davo Smith,

(Sorry I didn't notice your message before posting this reply. In the meantime, I'll do as you have suggested.)

Something astonishing happened. Other than adding new string, I edited values of existing string, which was also not updating. But as soon as one of the moodle user changed some settings using GUI ( I think he enabled "no authentication" under Plugins -> Authentication -> Manage authentication, but he don't remember that), the modified string value is appearing now but I'm not able to change that back.

I tried again enabling and disabling that setting but nothing is updating.

What else action could act equivalent to version change just make moodle to update things?