mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-51802 core: new template for quick editing a title
convert editing tag name to use new template
This commit is contained in:
parent
2f45a11ac4
commit
cdc5f9785b
23 changed files with 636 additions and 171 deletions
|
@ -179,8 +179,8 @@ class core_tag_manage_table extends table_sql {
|
|||
*/
|
||||
public function col_name($tag) {
|
||||
global $OUTPUT;
|
||||
$tagoutput = new core_tag\output\tag($tag);
|
||||
return $OUTPUT->render_from_template('core_tag/tagname', $tagoutput->export_for_template($OUTPUT));
|
||||
$tagoutput = new core_tag\output\tagname($tag);
|
||||
return $OUTPUT->render_from_template('core/inplace_editable', $tagoutput->export_for_template($OUTPUT));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
55
tag/classes/output/tagname.php
Normal file
55
tag/classes/output/tagname.php
Normal file
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains class core_tag\output\tagname
|
||||
*
|
||||
* @package core_tag
|
||||
* @copyright 2016 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_tag\output;
|
||||
|
||||
use context_system;
|
||||
use lang_string;
|
||||
use html_writer;
|
||||
use core_tag_tag;
|
||||
|
||||
/**
|
||||
* Class to preapare a tag name for display.
|
||||
*
|
||||
* @package core_tag
|
||||
* @copyright 2016 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tagname extends \core\output\inplace_editable {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param stdClass|core_tag $tag
|
||||
*/
|
||||
public function __construct($tag) {
|
||||
$editable = has_capability('moodle/tag:manage', context_system::instance());
|
||||
$edithint = new lang_string('editname', 'core_tag');
|
||||
$editlabel = new lang_string('newnamefor', 'core_tag', $tag->rawname);
|
||||
$value = $tag->rawname;
|
||||
$displayvalue = html_writer::link(core_tag_tag::make_url($tag->tagcollid, $tag->rawname),
|
||||
core_tag_tag::make_display_name($tag));
|
||||
parent::__construct('core_tag', 'tagname', $tag->id, $editable, $displayvalue, $value, $edithint, $editlabel);
|
||||
}
|
||||
}
|
|
@ -892,14 +892,12 @@ class core_tag_tag {
|
|||
$data['rawname'] = clean_param($data['rawname'], PARAM_TAG);
|
||||
$name = core_text::strtolower($data['rawname']);
|
||||
|
||||
if (!$name) {
|
||||
if (!$name || $data['rawname'] === $this->rawname) {
|
||||
unset($data['rawname']);
|
||||
} else if ($existing = static::get_by_name($this->tagcollid, $name, 'id')) {
|
||||
// Prevent the rename if a tag with that name already exists.
|
||||
if ($existing->id != $this->id) {
|
||||
debugging('New tag name already exists, you should check it before calling core_tag_tag::update()',
|
||||
DEBUG_DEVELOPER);
|
||||
unset($data['rawname']);
|
||||
throw new moodle_exception('namesalreadybeeingused', 'core_tag');
|
||||
}
|
||||
}
|
||||
if (isset($data['rawname'])) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue