From 6ee5e596b81e45088cb0f3efb32ed14829ecfd0b Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 6 Jun 2016 16:07:30 +0800 Subject: [PATCH 1/2] MDL-54837 tags: fixed bug when collection is locked also fixed fatal error for upgraded plugins that did not pass tag component to the tag form element --- lib/form/tags.php | 3 +++ tag/classes/output/tagareacollection.php | 11 ++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/form/tags.php b/lib/form/tags.php index 3a66e69b402..7f9bab6b74a 100644 --- a/lib/form/tags.php +++ b/lib/form/tags.php @@ -128,6 +128,9 @@ class MoodleQuickForm_tags extends MoodleQuickForm_autocomplete { */ public function onQuickFormEvent($event, $arg, &$caller) { if ($event === 'createElement') { + if (!is_array($arg[2])) { + $arg[2] = []; + } $arg[2] += array('itemtype' => '', 'component' => ''); } return parent::onQuickFormEvent($event, $arg, $caller); diff --git a/tag/classes/output/tagareacollection.php b/tag/classes/output/tagareacollection.php index cb845ad9482..a2928b7ee44 100644 --- a/tag/classes/output/tagareacollection.php +++ b/tag/classes/output/tagareacollection.php @@ -43,8 +43,17 @@ class tagareacollection extends \core\output\inplace_editable { * @param \stdClass $tagarea */ public function __construct($tagarea) { + if (!empty($tagarea->locked)) { + // If the tag collection for the current tag area is locked, display the + // name of the collection without possibility to edit it. + $tagcoll = \core_tag_collection::get_by_id($tagarea->tagcollid); + parent::__construct('core_tag', 'tagareacollection', $tagarea->id, false, + \core_tag_collection::display_name($tagcoll), $tagarea->tagcollid); + return; + } + $tagcollections = \core_tag_collection::get_collections_menu(true); - $editable = (count($tagcollections) > 1) && empty($tagarea->locked) && + $editable = (count($tagcollections) > 1) && has_capability('moodle/tag:manage', context_system::instance()); $areaname = core_tag_area::display_name($tagarea->component, $tagarea->itemtype); $edithint = new lang_string('edittagcollection', 'core_tag'); From 64e9180d2e88f224b35feabfb2f62973f121338c Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 7 Jun 2016 08:58:59 +0800 Subject: [PATCH 2/2] MDL-54837 tags: allow to specify static function as callback --- tag/classes/tag.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tag/classes/tag.php b/tag/classes/tag.php index 26ee6905147..02d568bab71 100644 --- a/tag/classes/tag.php +++ b/tag/classes/tag.php @@ -1297,7 +1297,7 @@ class core_tag_tag { require_once($CFG->dirroot . '/' . ltrim($tagarea->callbackfile, '/')); } $callback = $tagarea->callback; - return $callback($this, $exclusivemode, $fromctx, $ctx, $rec, $page); + return call_user_func_array($callback, [$this, $exclusivemode, $fromctx, $ctx, $rec, $page]); } return null; }