Merge branch 'MDL-87633_main' of https://github.com/marxjohnson/moodle
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
namespace qbank_viewquestionname\output;
|
||||
|
||||
use core\output\action_link;
|
||||
use core\output\inplace_editable;
|
||||
use core\output\named_templatable;
|
||||
use renderable;
|
||||
@@ -29,13 +30,29 @@ use renderable;
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class questionname extends inplace_editable implements named_templatable, renderable {
|
||||
public function __construct(\stdClass $question) {
|
||||
/**
|
||||
* Create the in-place editable based on the question data.
|
||||
*
|
||||
* @param \stdClass $question
|
||||
* @param action_link|null $actionlink If provided, the question name will link to the action link's URL, with the action link's
|
||||
* text used as the link title.
|
||||
* @throws \coding_exception
|
||||
*/
|
||||
public function __construct(\stdClass $question, ?action_link $actionlink = null) {
|
||||
global $OUTPUT;
|
||||
$formattedname = format_string($question->name);
|
||||
if ($actionlink) {
|
||||
$display = $OUTPUT->action_link($actionlink->url, $formattedname, attributes: ['title' => $actionlink->text]);
|
||||
} else {
|
||||
$display = $formattedname;
|
||||
}
|
||||
parent::__construct(
|
||||
'qbank_viewquestionname',
|
||||
'questionname',
|
||||
$question->id,
|
||||
question_has_capability_on($question, 'edit'),
|
||||
format_string($question->name), $question->name,
|
||||
$display,
|
||||
$question->name,
|
||||
get_string('edit_question_name_hint', 'qbank_viewquestionname'),
|
||||
get_string('edit_question_name_label', 'qbank_viewquestionname', (object) [
|
||||
'name' => $question->name,
|
||||
|
||||
+15
-1
@@ -34,7 +34,21 @@ class question_name_idnumber_tags_column extends viewquestionname_column_helper
|
||||
global $OUTPUT;
|
||||
|
||||
echo \html_writer::start_tag('div', ['class' => 'd-inline-flex flex-nowrap overflow-hidden w-100']);
|
||||
$questiondisplay = $OUTPUT->render(new \qbank_viewquestionname\output\questionname($question));
|
||||
$actions = $this->qbank->get_question_actions();
|
||||
$actionlink = null;
|
||||
foreach ($actions as $action) {
|
||||
// Use the first action we have permission to access as the link from the question name.
|
||||
$actionlink = $action->get_action_menu_link($question);
|
||||
if (!is_null($actionlink)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$questiondisplay = $OUTPUT->render(
|
||||
new \qbank_viewquestionname\output\questionname(
|
||||
$question,
|
||||
$actionlink,
|
||||
),
|
||||
);
|
||||
$labelfor = $this->label_for($question);
|
||||
if ($labelfor) {
|
||||
echo \html_writer::tag('label', $questiondisplay, [
|
||||
|
||||
@@ -40,3 +40,25 @@ Feature: Use the qbank view page to edit question title using in place edit feat
|
||||
And I press "Apply filters"
|
||||
And I should see "First question"
|
||||
And "Edit question name" "field" should not exist
|
||||
|
||||
Scenario: Question title links to the first question action
|
||||
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
|
||||
And I set the field "Filter type" to "Category"
|
||||
And I set the field "Category" to "Test questions"
|
||||
And I press "Apply filters"
|
||||
When I follow "First question"
|
||||
Then I should see "First question"
|
||||
And I should see "Close preview"
|
||||
|
||||
Scenario: Question title links to the first question action the user has permission to use
|
||||
Given the following "role capability" exists:
|
||||
| role | editingteacher |
|
||||
| moodle/question:usemine | prevent |
|
||||
| moodle/question:useall | prevent |
|
||||
Given I am on the "Test quiz" "mod_quiz > question bank" page logged in as "teacher1"
|
||||
And I set the field "Filter type" to "Category"
|
||||
And I set the field "Category" to "Test questions"
|
||||
And I press "Apply filters"
|
||||
When I follow "First question"
|
||||
Then I should see "Editing a True/False question"
|
||||
And I should not see "Close preview"
|
||||
|
||||
Reference in New Issue
Block a user