Skip to content

Commit 1d5fa76

Browse files
committed
fix: Don't show editing options that arent supported for the chosen image
Without this, after choosing one of the supported editing options for an SVG image - the tab navigation at the top listing editing types shows the ones that shouldn't be available - and if chosen, causes exceptions to be encountered.
1 parent 6afc5c7 commit 1d5fa76

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

imageclass.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,11 @@ public function flip_image($direction) {
217217
return $fileinfo['filename'];
218218
}
219219

220-
private function get_editing_options() {
221-
global $CFG;
222-
220+
/**
221+
* Get the list of editing options allowed for this image.
222+
* Not all editing types are supported for all image formats.
223+
*/
224+
public function get_editing_options() {
223225
$options = [
224226
'caption',
225227
'delete',
@@ -238,6 +240,14 @@ private function get_editing_options() {
238240
];
239241
}
240242

243+
return $options;
244+
}
245+
246+
private function get_editing_options_form() {
247+
global $CFG;
248+
249+
$options = $this->get_editing_options();
250+
241251
$html = '<form action="'.$CFG->wwwroot.'/mod/lightboxgallery/imageedit.php" method="post"/>'.
242252
'<input type="hidden" name="id" value="'.$this->cmid.'" />'.
243253
'<input type="hidden" name="image" value="'.$this->storedfile->get_filename().'" />'.
@@ -305,7 +315,7 @@ public function get_image_display_html($editing = false) {
305315
}
306316
$html .= $this->gallery->extinfo ? '<div class="lightbox-gallery-image-extinfo">'.$timemodified.
307317
'<br/>'.$filesize.'KB '.$this->width.'x'.$this->height.'px</div>' : '';
308-
$html .= ($editing ? $this->get_editing_options() : '');
318+
$html .= ($editing ? $this->get_editing_options_form() : '');
309319
$html .= '</div>'.
310320
'</div>'.
311321
'</div>';

imageedit.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@
5353
$buttonurl = new moodle_url('/mod/lightboxgallery/view.php', array('id' => $id, 'editing' => 1, 'page' => $page));
5454
$PAGE->set_button($OUTPUT->single_button($buttonurl, get_string('backtogallery', 'lightboxgallery')));
5555

56-
$edittypes = lightboxgallery_edit_types();
56+
$fs = get_file_storage();
57+
if (!$storedfile = $fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $image)) {
58+
throw new \moodle_exception(get_string('errornofile', 'lightboxgallery', $image));
59+
}
60+
$imageclass = new lightboxgallery_image($storedfile, $gallery, $cm);
61+
62+
$edittypes = lightboxgallery_edit_types(false, $imageclass);
5763

5864
$tabs = array();
5965
foreach ($edittypes as $type => $name) {
@@ -75,11 +81,6 @@
7581
$editclass = 'edit_'.$tab;
7682
$editinstance = new $editclass($gallery, $cm, $image, $tab);
7783

78-
$fs = get_file_storage();
79-
if (!$storedfile = $fs->get_file($context->id, 'mod_lightboxgallery', 'gallery_images', '0', '/', $image)) {
80-
throw new \moodle_exception(get_string('errornofile', 'lightboxgallery', $image));
81-
}
82-
8384
if ($editinstance->processing() && confirm_sesskey()) {
8485
$params = array(
8586
'context' => $context,
@@ -98,22 +99,20 @@
9899
redirect($CFG->wwwroot.'/mod/lightboxgallery/imageedit.php?id='.$cm->id.'&image='.$editinstance->image.'&tab='.$tab);
99100
}
100101

101-
$image = new lightboxgallery_image($storedfile, $gallery, $cm);
102-
103102
$table = new html_table();
104103
$table->width = '*';
105104

106105
if ($editinstance->showthumb) {
107106
$table->attributes = array('style' => 'margin-left:auto;margin-right:auto;');
108107
$table->align = array('center', 'center');
109108
$table->size = array('*', '*');
110-
$table->data[] = array('<img src="'.$image->get_thumbnail_url().
111-
'" alt="" /><br /><span title="'.$image->get_image_caption().'">'.
112-
$image->get_image_caption().'</span>', $editinstance->output($image->get_image_caption()));
109+
$table->data[] = array('<img src="'.$imageclass->get_thumbnail_url().
110+
'" alt="" /><br /><span title="'.$imageclass->get_image_caption().'">'.
111+
$imageclass->get_image_caption().'</span>', $editinstance->output($imageclass->get_image_caption()));
113112
} else {
114113
$table->align = array('center');
115114
$table->size = array('*');
116-
$table->data[] = array($editinstance->output($image->get_image_caption()));
115+
$table->data[] = array($editinstance->output($imageclass->get_image_caption()));
117116
}
118117

119118
echo $OUTPUT->header();

locallib.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function lightboxgallery_config_defaults() {
113113
}
114114
}
115115

116-
function lightboxgallery_edit_types($showall = false) {
116+
function lightboxgallery_edit_types($showall = false, $image = null) {
117117
$result = array();
118118

119119
$disabledplugins = explode(',', get_config('lightboxgallery', 'disabledplugins'));
@@ -122,6 +122,9 @@ function lightboxgallery_edit_types($showall = false) {
122122
$disabledplugins[] = 'crop';
123123

124124
$edittypes = get_list_of_plugins('mod/lightboxgallery/edit');
125+
if ($image !== null && !$showall) {
126+
$edittypes = array_intersect($image->get_editing_options(), $edittypes);
127+
}
125128

126129
foreach ($edittypes as $edittype) {
127130
if ($showall || !in_array($edittype, $disabledplugins)) {

0 commit comments

Comments
 (0)