Problem/Motivation
BlockClassConfirmBulkOperationForm::getQuestion() returns $message_to_confirm, but the variable is only assigned inside the switch ($this->operation) branches and is never initialised. The block_class.confirm_bulk_operation route takes {operation} as a free URL parameter, so any value that matches no case reaches the return with the variable unset.
Steps to reproduce
- Install Block Class 4.0.x-dev.
- As a user with the
administer block classespermission, visit:
/admin/config/content/block-class/confirm-bulk-operation/bogus_op/x/x/x/x/x/xThe page returns HTTP 200 and renders Warning: Undefined variable $message_to_confirm.
Proposed resolution
Initialise the variable before the switch, as already proposed in MR !5 on the closed issue #3279758:
public function getQuestion() { $message_to_confirm = ""; switch ($this->operation) {
Worth considering as part of the same change: the insert case falls through without assigning a message, so a legitimate insert operation also returns an empty question.
Remaining tasks
- Open a merge request against 4.0.x, crediting hswong3i for the original change in MR !5.
- Review and test.
User interface changes
None, other than the PHP warning no longer being rendered on the confirmation page.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3619190 after.png | 129.74 KB | csakiistvan |
| #6 | 3619190 before.png | 309.87 KB | csakiistvan |
Issue fork block_class-3619190
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
akhilsoni commentedI have created a merge request with the proposed fix.
Initialised $message_to_confirm before the switch statement in BlockClassConfirmBulkOperationForm::getQuestion() to prevent the undefined variable warning. I've also added a functional test to cover the invalid operation scenario.
Coding standards pass cleanly with PHPCS. Please review.
Comment #5
csakiistvanComment #6
csakiistvan✅ Tested and works — reproduced the
Undefined variable $message_to_confirmwarning on 4.0.x at/admin/config/content/block-class/confirm-bulk-operation/bogus_op/x/x/x/x/x/x, then applied MR !87, rebuilt caches and reloaded the page: the warning is gone. The fix resolves the reported warning.Comment #7
dydave commentedThanks a lot everyone for the great work! 🙏
I'll do a pass on module's 4.x issues, this week and the following.
More to come very soon ... 😊
Thanks again!
Comment #8
dydave commentedGreat job everyone!! Thanks a lot!! 🙏
Akhil (@akhilsoni), great documentation job of the issue and the merge request looks great. 🤩
Thanks a lot for the added phpunit test case... that's super helpful!
Indeed, I've got the following warning appearing in my VSCode:
So these changes should definitely be accepted.
However, I think you've pointed out another more annoying issue:
Why does the following URL not return a 404? 😅
/admin/config/content/block-class/confirm-bulk-operation/bogus_op/x/x/x/x/x/xThe
bogus_opoperation does not exist, so this page actually does not make any sense and there is currently no way to navigate to this page though the interface....It probably slipped through the code cracks and since submitting the form on this page does nothing, I assume ... it just does no harm (?!). 😅
Anyway... this should probably be the object of a follow-up issue.
Now, I'll get to the code review, merging, and moving on...
Comment #10
dydave commentedOK, I tested this locally, made some minor changes to the tests by adding two more checks on the tested page.
Since all the tests were still passing green 🟢, I went ahead and merged the changes above at #9. 🥳
I created the follow-up task #3627167: Refactor BlockClassConfirmBulkOperationForm operations and pages to address the issue with the validation of module's route parameters, in particular the selected bulk operation.
Personally, I think "ideally" it would be great if the module could rely on a different module to perform bulk operations.
But that's part of a much wider scope and discussion.
Marking issue as Fixed for now.
Thanks again! 🙏