#225 Allow element plugins to control if they can be added
This commit is contained in:
parent
97498b54a0
commit
f16434575d
2 changed files with 15 additions and 2 deletions
|
@ -352,6 +352,16 @@ abstract class element {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This defines if an element plugin can be added to a certificate.
|
||||||
|
* Can be overridden if an element plugin wants to take over the control.
|
||||||
|
*
|
||||||
|
* @return bool returns true if the element can be added, false otherwise
|
||||||
|
*/
|
||||||
|
public static function allow_add() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles rendering the element on the pdf.
|
* Handles rendering the element on the pdf.
|
||||||
*
|
*
|
||||||
|
|
|
@ -412,11 +412,14 @@ class element_helper {
|
||||||
$classname = '\\customcertelement_' . $foldername . '\\element';
|
$classname = '\\customcertelement_' . $foldername . '\\element';
|
||||||
// Ensure the necessary class exists.
|
// Ensure the necessary class exists.
|
||||||
if (class_exists($classname)) {
|
if (class_exists($classname)) {
|
||||||
|
// Additionally, check if the user is allowed to add the element at all.
|
||||||
|
if ($classname::allow_add()) {
|
||||||
$component = "customcertelement_{$foldername}";
|
$component = "customcertelement_{$foldername}";
|
||||||
$options[$foldername] = get_string('pluginname', $component);
|
$options[$foldername] = get_string('pluginname', $component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
\core_collator::asort($options);
|
\core_collator::asort($options);
|
||||||
return $options;
|
return $options;
|
||||||
|
|
Loading…
Reference in a new issue