I’m currently trying to work with access rights in my block plugin.
Moodle version 4.3.7
The file is located in the blocks/lbtb/ folder
To do this, I entered the following into access.php:
$capabilities = array(
'block/lbtb:canreadlbtbblock' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
),
'block/lbtb:canwritelbtbblock' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
),
);
I would like to enable the query with has_capability.
This is what my file looks like where I want to query:
use core_externalutil as external_util;
require_once(__DIR__ . '/../../config.php');
class block_lbtb extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_lbtb');
}
function has_config(){
return true;
}
public function get_content() {
global $DB, $CFG, $OUTPUT;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
// Add logic here to define your template data or any other content.
$getswconfig = get_config('block_lbtb', 'sw');
$getszconfig = get_config('block_lbtb', 'sz');
$contextblock = context_system::instance();
if (has_capabilty('block/lbtb:canwritelbtbblock', $contextblock)) {
$visibility = '';
} else {
$visibility = 'display: none;';
}
if ($getswconfig == 0) {
$getsw = 'lbtbbuttongreen';
} else {
$getsw = 'lbtbbuttonred';
}
if ($getszconfig == 0) {
$getsz = 'lbtbbuttongreen';
} else {
$getsz = 'lbtbbuttonred';
}
$data = [
'buttoncolorsw' => $getsw,
'buttoncolorsz' => $getsz,
'visibility' => $visibility,
];
$this->content->text = $OUTPUT->render_from_template('block_lbtb/content', $data);
return $this->content;
}
}
I get this error:
Fehler: Call to undefined function has_capabilty()
Debug info:
Error code: generalexceptionmessage
Stack trace:
line 34 of /blocks/lbtb/block_lbtb.php: Error thrown
Line 34:
if (has_capabilty('block/lbtb:canreadlbtbblock', $contextblock)) {