-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.4, 4.5
The call to add_block_at_end_of_default_region can return null, but if it does, an exception is thrown (block_not_on_page_exception) when find_instance is called.
This can happen if a plugin overrides add_block_at_end_of_default_region and intentionally returns null in order to prevent a user adding a block:
https://moodle.org/plugins/tool_blocksmanager
https://github.com/moodle/moodle/blob/main/blocks/edit_form.php#L434-L452
Steps to reproduce:
- Setup a Moodle site
- Install the tool_blocksmanager plugin
- Open the site root directory in your terminal
- git clone -b MOODLE_404_STABLE git@github.com:catalyst/moodle_tool_blocksmanager.git admin/tool/blocksmanager
- Navigate to /admin/tool/blocksmanager/region.php
- Click Add new locked region
- Set region to side-pre
- Select all categories (e.g. Category 1)
- Set Allow to add? to No
- Save changes
- Navigate to a course in one of the selected categories
- Log in as a teacher (setting role to teacher won't work)
- Attempt to add a block (e.g. Text block)
- Verify you see an exception message
- Apply the MDL-83044 patch
- Attempt to add a block
- Verify you see a red notice banner instead