What is the right way to customize a button's text

What is the right way to customize a button's text

de Darren LaRue -
Número de respuestas: 10

Version 2.7.2 (Build 20140911)

I want to change the text on the button that launches the quiz activity in a course.  The button currently reads "Attempt Quiz Now".  However, because I design most of our quizzes with informational (learning) slides intermixed with the questions, the activity really isn't just a quiz, but rather a learning module.  I would like to change the button to something else like "Begin Learning Module" so the students don't "freak out" thinking they are about to be tested over something they've not been presented with.

All help appreciated...

Promedio de valoraciones: -
En respuesta a Darren LaRue

Re: What is the right way to customize a button's text

de Just H -

If wanting the change sitewide easiest option would be to use the in-buit language customisation functionality.

En respuesta a Just H

Re: What is the right way to customize a button's text

de Darren LaRue -

Thank you.  I've used language customization in other places, but didn't think about it for this issue.  It worked like a charm.

En respuesta a Darren LaRue

Re: What is the right way to customize a button's text

de Just H -

Good to hear; happy Moodling sonrisa

En respuesta a Just H

Re: What is the right way to customize a button's text

de Greg Rudl -

About can you make this change for just a course?

En respuesta a Greg Rudl

Re: What is the right way to customize a button's text

de Just H -

Changing it just for a specific course would be more complex and I can't say I've stumbled across any examples of that use case before. Perhaps someone could come up with some code or a module but that's above my knowledge I'm afraid.

En respuesta a Just H

Re: What is the right way to customize a button's text

de Greg Rudl -

Thanks for the reply, but what I really meant was for a particular Quiz in a course. Sorry for the confusion. I could say there would be many uses for such a thing...submit [quiz, test, exam, translation assessment] now, start, begin ...

En respuesta a Greg Rudl

Re: What is the right way to customize a button's text

de Frankie Kam -
Imagen de Plugin developers

This thread actually belongs in the Quiz module discussion forum.

A famous politician says "Yes you can". The BEST thing about Moodle is you can do virtually anything with it. You, Sir, have come to the right place.

I have exactly the same requirements as you. I am using a "Quiz activity A" to give instructions about the "Quiz activity B" which is placement test (which is the actual quiz activity that I want to test my students on).

The purpose of my "Quiz activity A" is to give students time to read instructions about the real quiz. They only have 1 hour to take the placement test, and I don't want them to waste time reading through 5 screenfuls of information before taking the placement test. Hence the existence of this "Readme" activity - "Quiz activity A" - which itself is a Moodle quiz activity. When my students click on "Read the README" activity, and they see the "Attempt quiz" button, they will get confused because they think that by clicking that "Attempt quiz" button, they will be taking actual placement test. Since they are now accessing "Quiz activity A" - my "Read the README" activity, it is better if they see a button with the text "Read the Instructions" instead of the ubiquitous "Attempt quiz" button.

I am using Moodle 2.7.2. Here's what I did (it's really ugly - crude but effective, but you will get the idea):

Step1. Edit the /mod/quiz/view.php file.

Somewhere around line 206


Here's the code in softcopy:

        if ($canattempt) {
            $viewobj->preventmessages = $viewobj->accessmanager->prevent_new_attempt(
                    $viewobj->numattempts, $viewobj->lastfinishedattempt);
            if ($viewobj->preventmessages) {
                $viewobj->buttontext = '';
            } else if ($viewobj->numattempts == 0) {
                $viewobj->buttontext = get_string('attemptquiznow', 'quiz');
            } else {
                $viewobj->buttontext = get_string('reattemptquiz', 'quiz');
            }
        } else if ($canpreview) {
            $viewobj->buttontext = get_string('previewquiznow', 'quiz');
        }

Since my "Quiz activity A" name is "Read the README",  here's what my modified code looks like:

        if ($canattempt) {
            $notquiz = "Read the README";
            $viewobj->preventmessages = $viewobj->accessmanager->prevent_new_attempt(
                       $viewobj->numattempts, $viewobj->lastfinishedattempt);
            if ($viewobj->preventmessages) {
                $viewobj->buttontext = '';
            } else if ($viewobj->numattempts == 0) {
           if($notquiz ===format_string($quiz->name))
                $viewobj->buttontext = get_string('attemptquiznow1', 'quiz');
           else

                 $viewobj->buttontext = get_string('attemptquiznow', 'quiz');
            } else {
                 if($notquiz ===format_string($quiz->name))
                     $viewobj->buttontext = get_string('reattemptquiz1', 'quiz');
                  else

                      $viewobj->buttontext = get_string('reattemptquiz', 'quiz');
            }

        } else if ($canpreview) {
            $viewobj->buttontext = get_string('previewquiznow', 'quiz');
        }

What the logic is saying is this. "Moodle, if I am accessing a quiz activity named 'Read the README', then display the text referred to by the identifier (tag) attemptquiznow1 and reattemptquiz1.

Now for this to work, of course I have to create the tags attemptquiznow1 and reattemptquiz1 inside the mod/quiz/lang/en/quiz.php language file. So that's what I did! I added these two lines:



Don't forget to clear your cache with Settings > Site Administration > Development > Purge all caches.

In this way, whenever the student is doing the "Quiz activity A" - my "Read the README" quiz activity, they see the buttons "Read the instructions" and "Re-read the instructions" instead of buttons with the text "Attempt quiz now" and "Re-attempt quiz" on them. 

When they take the actual placement test, which is also a Moodle quiz activity, they will see the buttons "Attempt quiz now" and "Re-attempt quiz". 

That is the way I avoid confusion and frustration. So if you find this useful and is something that will solve your requirements, then you know what to do. Reward me by clicking the "Useful" link below.
guiño

Regards
Frankie Kam 

En respuesta a Frankie Kam

Re: What is the right way to customize a button's text

de AL Rachels -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers

Hi Frankie,

A much simpler, easier method, that does not require modifying any Moodle code, can be done using the Generico filter and < div > ...the text...< / div > tags that provides a scroll bar. And then you also can do many other things with Generico, to dress up your site, courses, and activities.

I add as much text/directions as I want to, right in the quiz description, and place a checkmark in edit mode for Display description on course page. I then place a Generico, Gradient_formatted_toggle filter as the first thing in the description. It has two parts, a start and and end. In between them you can place a whole BUNCH of text. Basically, whatever you want. Right after the start part of the filter, in HTML mode, I place an opening div tag that includes a scroll for overflow. After the text, but before the closing part of the toggle filter, I put the closing div tag.

In topic view, everyone sees this:

Still in topic view, when they click the button, it reveals this:


If they go ahead and click on the quiz link, they can also see the toggle there:

And after click:



En respuesta a AL Rachels

Re: What is the right way to customize a button's text

de Frankie Kam -
Imagen de Plugin developers

The Generico filter must be the greatest thing since sliced bread!
It's what I will need to end the epidemic of unchecked and undocumented hacks to Moodle code.
Thanks for sharing this. I will be checking it out. Blog about it too.

En respuesta a Frankie Kam

Re: What is the right way to customize a button's text

de AL Rachels -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers

In a way it is the best thing since, "sliced bread!" It is truly amazing all the different things you can do with Generico filters, and if you use the PoodLL3 filter, you can also do all the same things with it. In fact, the same filter "bundles" will work in either filter.

Essentially, if you were to install the Generico filter plugin just to be able to do what I showed in my last post, you will get the added benefit of being able to do many more things, as well, simply because, by default you can have 20 filters defined. Plus, you can up that number. In one of my sites I currently have it set for 45 filters. You can even place filters inside of filters. For instance, many times when I use a gradient toggle to decrease the size of the description, I also personalize those directions by adding a firstname filter inside it. The front page of my sites will greet you by your first and last names and welcome you to the site.

Just a few days ago, someone in another forum was wanting to know if it was possible to have multiple feedback phrases for the overall quiz feedback so that students did not all get the same feedback. It only took me about an hour to make a filter that will give one of ten randomly selected phrases. In fact, since the quiz already can vary the feedback based on a score range, I've been working on multiple versions - one set for a perfect score, plus others for score ranges of A or high, B-C or moderate, and Encouragement for barely passing and lower, to urge them to improve next time. No more work dreaming up what to set for the feedback ranges, just a couple of clicks and it's automatic.