forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-52869 course: use inplace_editable for activity names
- Loading branch information
1 parent
e8952c5
commit f59f89b
Showing
20 changed files
with
404 additions
and
732 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@block @block_main_menu | ||
Feature: Edit activities in main menu block | ||
In order to use main menu block | ||
As an admin | ||
I need to add and edit activities there | ||
|
||
@javascript | ||
Scenario: Edit name of acitivity in-place in site main menu block | ||
Given I log in as "admin" | ||
And I am on site homepage | ||
And I navigate to "Turn editing on" node in "Front page settings" | ||
When I add a "Forum" to section "0" and I fill the form with: | ||
| Forum name | My forum name | | ||
And I click on "Edit title" "link" in the "//.[contains(@class,'block_site_main_menu')]//li[contains(.,'My forum name')]" "xpath_element" | ||
And I set the field "New name for activity My forum name" to "New forum name" | ||
And I press key "13" in the field "New name for activity My forum name" | ||
Then I should not see "My forum name" | ||
And I should see "New forum name" | ||
And I follow "New forum name" | ||
And I should not see "My forum name" | ||
And I should see "New forum name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
blocks/social_activities/tests/behat/edit_activities.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@block @block_social_activities | ||
Feature: Edit activities in social activities block | ||
In order to use social activities block | ||
As a teacher | ||
I need to add and edit activities there | ||
|
||
@javascript | ||
Scenario: Edit name of acitivity in-place in social activities block | ||
Given the following "courses" exist: | ||
| fullname | shortname | format | | ||
| Course 1 | C1 | social | | ||
And the following "users" exist: | ||
| username | firstname | lastname | | ||
| user1 | User | One | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| user1 | C1 | editingteacher | | ||
Given I log in as "user1" | ||
And I follow "Course 1" | ||
And I turn editing mode on | ||
And I set the field "Add an activity to section 'section 0'" to "Forum" | ||
And I set the field "Forum name" to "My forum name" | ||
And I press "Save and return to course" | ||
And I click on "Edit title" "link" in the "//.[contains(@class,'block_social_activities')]//li[contains(.,'My forum name')]" "xpath_element" | ||
And I set the field "New name for activity My forum name" to "New forum name" | ||
And I press key "13" in the field "New name for activity My forum name" | ||
Then I should not see "My forum name" in the "Social activities" "block" | ||
And I should see "New forum name" | ||
And I follow "New forum name" | ||
And I should not see "My forum name" | ||
And I should see "New forum name" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?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\course_module_name | ||
* | ||
* @package core_course | ||
* @copyright 2016 Marina Glancy | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_course\output; | ||
|
||
use context_module; | ||
use lang_string; | ||
use cm_info; | ||
|
||
/** | ||
* Class to prepare a course module name for display and in-place editing | ||
* | ||
* @package core_course | ||
* @copyright 2016 Marina Glancy | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class course_module_name extends \core\output\inplace_editable { | ||
|
||
/** @var cm_info */ | ||
protected $cm; | ||
|
||
/** @var array */ | ||
protected $displayoptions; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param cm_info $cm | ||
* @param bool $editable | ||
* @param array $displayoptions | ||
*/ | ||
public function __construct(cm_info $cm, $editable, $displayoptions = array()) { | ||
$this->cm = $cm; | ||
$this->displayoptions = $displayoptions; | ||
$value = $cm->name; | ||
$edithint = new lang_string('edittitle'); | ||
$editlabel = new lang_string('newactivityname', '', $cm->get_formatted_name()); | ||
$editable = $editable && has_capability('moodle/course:manageactivities', | ||
context_module::instance($cm->id)); | ||
parent::__construct( | ||
'core_course', 'activityname', $cm->id, $editable, $value, $value, $edithint, $editlabel); | ||
} | ||
|
||
/** | ||
* Export this data so it can be used as the context for a mustache template (core/inplace_editable). | ||
* | ||
* @param renderer_base $output typically, the renderer that's calling this function | ||
* @return array data context for a mustache template | ||
*/ | ||
public function export_for_template(\renderer_base $output) { | ||
global $PAGE; | ||
$courserenderer = $PAGE->get_renderer('core', 'course'); | ||
$this->displayvalue = $courserenderer->course_section_cm_name_title($this->cm, $this->displayoptions); | ||
if (strval($this->displayvalue) === '') { | ||
$this->editable = false; | ||
} | ||
return parent::export_for_template($output); | ||
} | ||
|
||
/** | ||
* Updates course module name | ||
* | ||
* @param int $itemid course module id | ||
* @param string $newvalue new name | ||
* @return static | ||
*/ | ||
public static function update($itemid, $newvalue) { | ||
list($course, $cm) = get_course_and_cm_from_cmid($itemid); | ||
$context = context_module::instance($cm->id); | ||
// Check access. | ||
require_login($course, false, $cm, true, true); | ||
require_capability('moodle/course:manageactivities', $context); | ||
// Update value. | ||
set_coursemodule_name($cm->id, $newvalue); | ||
// Return instance. | ||
$cm = get_fast_modinfo($course)->get_cm($cm->id); | ||
return new static($cm, true); | ||
} | ||
} |
Oops, something went wrong.