blocks and capabilities

blocks and capabilities

by john doe -
Number of replies: 5

Hello to the community,
I try to set up a block that shows up on the courses for a certain type of user. In addition, the contents of this block is variable depending on the course category. I tried in a first time only change the contents of the block depending on the user's role and, even for this task which sounds simple, I have difficulty.

I created a acces.php file containing the following code:

$ capabilities = array (

'block / xxx: view' => array (

'captype' => 'read',

'contextlevel' => CONTEXT_COURSE,

'archetypes' => array (

'student' => CAP_PROHIBIT,

'admin' => CAP_ALLOW

)));

And the function get_content my block:

 

if (has_capability ('block / XXX: view', $ this-> context)) {

$ this-> content-> text = "<br> flag 01";}

else {

$ this-> content-> text = "<br> flag 02";}

Could you tell me where I'm wrong, and how can I progress

Average of ratings: -
In reply to john doe

Re: blocks and capabilities

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

All the spaces in 'block / XXX: view' look wrong. Do you have debugging set to DEVELOPER? If not, try it.

In reply to Tim Hunt

Re: blocks and capabilities

by john doe -

where can I find the "debugging set to DEVELOPER"? I don't know what it is.

In reply to john doe

Re: blocks and capabilities

by john doe -

There is no problem with the debugging. Do you have any idea on the way to display of my block, only on courses, only for one type of user?

Can the following instructions guarantee the display only on a course? : 'contextlevel' => CONTEXT_COURSE,"

Thank you in advance for your answers.