MDL-66399 editor: Only set h5p settings if user can deploy
authorAndrew Nicols <andrew@nicols.co.uk>
Tue, 5 Nov 2019 06:19:08 +0000 (14:19 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Tue, 5 Nov 2019 06:19:08 +0000 (14:19 +0800)
lib/form/editor.php

index f0631f9..1b6d895 100644 (file)
@@ -390,21 +390,24 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatab
             $subtitle_options->env = 'editor';
             $subtitle_options->itemid = $draftitemid;
 
-            // H5P plugin.
-            $args->accepted_types = array('.h5p');
-            $h5poptions = initialise_filepicker($args);
-            $h5poptions->context = $ctx;
-            $h5poptions->client_id = uniqid();
-            $h5poptions->maxbytes  = $this->_options['maxbytes'];
-            $h5poptions->areamaxbytes  = $this->_options['areamaxbytes'];
-            $h5poptions->env = 'editor';
-            $h5poptions->itemid = $draftitemid;
+            if (has_capability('moodle/h5p:deploy', $ctx)) {
+                // Only set H5P Plugin settings if the user can deploy new H5P content.
+                // H5P plugin.
+                $args->accepted_types = array('.h5p');
+                $h5poptions = initialise_filepicker($args);
+                $h5poptions->context = $ctx;
+                $h5poptions->client_id = uniqid();
+                $h5poptions->maxbytes  = $this->_options['maxbytes'];
+                $h5poptions->areamaxbytes  = $this->_options['areamaxbytes'];
+                $h5poptions->env = 'editor';
+                $h5poptions->itemid = $draftitemid;
+                $fpoptions['h5p'] = $h5poptions;
+            }
 
             $fpoptions['image'] = $image_options;
             $fpoptions['media'] = $media_options;
             $fpoptions['link'] = $link_options;
             $fpoptions['subtitle'] = $subtitle_options;
-            $fpoptions['h5p'] = $h5poptions;
         }
 
         //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation.