From fcaf1fefd586963a9f5d9d783fc2d981f8e8d1fd Mon Sep 17 00:00:00 2001 From: Alexander Bias Date: Wed, 8 Aug 2018 13:45:20 +0200 Subject: [PATCH] #225 Allow element plugins to control if they can be added --- classes/element.php | 10 ++++++++++ classes/element_helper.php | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/classes/element.php b/classes/element.php index 7acad0b..134414f 100644 --- a/classes/element.php +++ b/classes/element.php @@ -352,6 +352,16 @@ abstract class element { 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. * diff --git a/classes/element_helper.php b/classes/element_helper.php index e365c70..b9775bb 100644 --- a/classes/element_helper.php +++ b/classes/element_helper.php @@ -412,8 +412,11 @@ class element_helper { $classname = '\\customcertelement_' . $foldername . '\\element'; // Ensure the necessary class exists. if (class_exists($classname)) { - $component = "customcertelement_{$foldername}"; - $options[$foldername] = get_string('pluginname', $component); + // Additionally, check if the user is allowed to add the element at all. + if ($classname::allow_add()) { + $component = "customcertelement_{$foldername}"; + $options[$foldername] = get_string('pluginname', $component); + } } } }