From d2e870f221020cc4c7c61d513757005ce387687e Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 26 Jan 2026 13:43:13 +0000 Subject: [PATCH] MDL-87633 qbank_viewquestioname: Link question name to the first action This updates the question name column to link the name of each question to the first action in the list of question actions. The action_link is passed to the questionname inplace editable class, where its URL and text are used as the URL and title of a link containing the question name. --- .../classes/output/questionname.php | 21 ++++++++++++++++-- .../question_name_idnumber_tags_column.php | 16 +++++++++++++- .../behat/question_in_place_editing.feature | 22 +++++++++++++++++++ 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/public/question/bank/viewquestionname/classes/output/questionname.php b/public/question/bank/viewquestionname/classes/output/questionname.php index 4444c809217..5b417944a9d 100644 --- a/public/question/bank/viewquestionname/classes/output/questionname.php +++ b/public/question/bank/viewquestionname/classes/output/questionname.php @@ -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, diff --git a/public/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php b/public/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php index 97063dc5980..11a5301ac2d 100644 --- a/public/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php +++ b/public/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php @@ -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, [ diff --git a/public/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature b/public/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature index 5b0b6a9ce04..d5a324fb855 100644 --- a/public/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature +++ b/public/question/bank/viewquestionname/tests/behat/question_in_place_editing.feature @@ -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"