Can i give students edit access to one block?

Can i give students edit access to one block?

av Tom M -
Antall svar: 3

Hi,

I've made some code in a custom block that allows every user to save his own settings inside it (code finished, it works). Now the only logical action is to allow every user to edit the block, so they can reach the settings page.

However, i don't want to give all users the global moodle/site:manageblocks role, because that's plain silly.

How can i say "all users can edit this specific block"?

Gjennomsnittlig vurdering: -
Som svar til Tom M

Re: Can i give students edit access to one block?

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Just make a new script blocks/myblock/settings.php or something like that, which lets each user edit their settings.

Then put a link to that script in the block.
Som svar til Tim Hunt

Re: Can i give students edit access to one block?

av Tom M -

Documentation on settings.php is very sparse, but it seems to be about admin settings (not student users) only, and it only works when the file is included by admin/settings/plugins.php.

Can you give me a more specific example? I've looked at course_list, and it's just a pretty empty specifications file.. Thanks in advance!

Som svar til Tom M

Re: Can i give students edit access to one block?

av Tim Hunt -
Bilde av Core developers Bilde av Documentation writers Bilde av Particularly helpful Moodlers Bilde av Peer reviewers Bilde av Plugin developers
Sorry, i was forgetting that settings.php was a special file. I was not taking about a settings.php file.

What I meant was create a new stand-along PHP script, let us say
blocks/myblock/myscript.php

Then, the the HTML of the block, add a link to $CFG->wwwroot . 'blocks/myblock/myscript.php'


myscript.php should be a typical Moodle script:

require_once('../../config.php');

require_login(...);
requrire_capability(...);

// Do something.


In your case, Do something probably means display a form, and the process it when it is submitted.

I think course/request.php is a reasonably simple example of a typical Moodle script that does something like this.