$this->config->numberoftags = 80;
}
+ if (empty($this->config->tagtype)) {
+ $this->config->tagtype = '';
+ }
+
+ if (empty($this->config->ctx)) {
+ $this->config->ctx = 0;
+ }
+
+ if (empty($this->config->rec)) {
+ $this->config->rec = 1;
+ }
+
+ if (empty($this->config->tagcoll)) {
+ $this->config->tagcoll = 0;
+ }
+
if ($this->content !== NULL) {
return $this->content;
}
// Get a list of tags.
- require_once($CFG->dirroot.'/tag/locallib.php');
-
- $this->content->text = tag_print_cloud(null, $this->config->numberoftags, true);
+ $tagcloud = core_tag_collection::get_tag_cloud($this->config->tagcoll,
+ $this->config->tagtype,
+ $this->config->numberoftags,
+ 'name', '', $this->page->context->id, $this->config->ctx, $this->config->rec);
+ $this->content->text = $OUTPUT->render_from_template('core_tag/tagcloud', $tagcloud->export_for_template($OUTPUT));
return $this->content;
}
*/
class block_tags_edit_form extends block_edit_form {
protected function specific_definition($mform) {
+ global $CFG;
// Fields for editing HTML block title and contents.
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
$mform->setType('config_title', PARAM_TEXT);
$mform->setDefault('config_title', get_string('pluginname', 'block_tags'));
+ $this->add_collection_selector($mform);
+
$numberoftags = array();
for ($i = 1; $i <= 200; $i++) {
$numberoftags[$i] = $i;
}
$mform->addElement('select', 'config_numberoftags', get_string('numberoftags', 'blog'), $numberoftags);
$mform->setDefault('config_numberoftags', 80);
+
+ $defaults = array(
+ 'official' => get_string('officialonly', 'block_tags'),
+ '' => get_string('anytype', 'block_tags'));
+ $mform->addElement('select', 'config_tagtype', get_string('defaultdisplay', 'block_tags'), $defaults);
+ $mform->setDefault('config_tagtype', '');
+
+ $defaults = array(0 => context_system::instance()->get_context_name());
+ $parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
+ if ($parentcontext->contextlevel > CONTEXT_COURSE) {
+ $coursecontext = $parentcontext->get_course_context();
+ $defaults[$coursecontext->id] = $coursecontext->get_context_name();
+ }
+ if ($parentcontext->contextlevel != CONTEXT_SYSTEM) {
+ $defaults[$parentcontext->id] = $parentcontext->get_context_name();
+ }
+ $mform->addElement('select', 'config_ctx', get_string('taggeditemscontext', 'block_tags'), $defaults);
+ $mform->addHelpButton('config_ctx', 'taggeditemscontext', 'block_tags');
+ $mform->setDefault('config_ctx', 0);
+
+ $mform->addElement('advcheckbox', 'config_rec', get_string('recursivecontext', 'block_tags'));
+ $mform->addHelpButton('config_rec', 'recursivecontext', 'block_tags');
+ $mform->setDefault('config_rec', 1);
+ }
+
+ /**
+ * Add the tag collection selector
+ *
+ * @param object $mform the form being built.
+ */
+ protected function add_collection_selector($mform) {
+ $tagcolls = core_tag_collection::get_collections_menu(false, false, get_string('anycollection', 'block_tags'));
+ if (count($tagcolls) <= 1) {
+ return;
+ }
+
+ $tagcollssearchable = core_tag_collection::get_collections_menu(false, true);
+ $hasunsearchable = false;
+ foreach ($tagcolls as $id => $name) {
+ if ($id && !array_key_exists($id, $tagcollssearchable)) {
+ $hasunsearchable = true;
+ $tagcolls[$id] = $name . '*';
+ }
+ }
+
+ $mform->addElement('select', 'config_tagcoll', get_string('tagcollection', 'block_tags'), $tagcolls);
+ if ($hasunsearchable) {
+ $mform->addHelpButton('config_tagcoll', 'tagcollection', 'block_tags');
+ }
+ $mform->setDefault('config_tagcoll', 0);
}
}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+$string['anycollection'] = 'Any';
+$string['anytype'] = 'All';
$string['configtitle'] = 'Block title';
$string['disabledtags'] = 'Tags are disabled';
$string['defaultdisplay'] = 'Tag type to display';
+$string['officialonly'] = 'Only official';
$string['pluginname'] = 'Tags';
+$string['recursivecontext'] = 'Include child contexts';
+$string['recursivecontext_help'] = 'If unchecked, tags of items in the context specified above will be displayed excluding underlying contexts, for example, you can search on course level only without searching inside course activities';
+$string['tagcollection'] = 'Tag collection';
+$string['tagcollection_help'] = 'Select tag collection to display tags from. If you choose "Any" '
+ . 'the tags from all collections except for those marked with * will be displayed';
+$string['taggeditemscontext'] = 'Tagged items context';
+$string['taggeditemscontext_help'] = 'You can limit the tag cloud to the tags that are present in the current course category, course or module';
$string['tags:addinstance'] = 'Add a new tags block';
$string['tags:myaddinstance'] = 'Add a new tags block to Dashboard';
-// Deprecated since 3.0
+// Deprecated since 3.0.
$string['add'] = 'Add';
$string['alltags'] = 'All tags:';