Skip to content

Cleanup: inline coursemodule_standard_elements, merge event_observer into observer#74

Draft
Copilot wants to merge 5 commits into
experimentalfrom
copilot/add-dropdown-field-assignment-settings
Draft

Cleanup: inline coursemodule_standard_elements, merge event_observer into observer#74
Copilot wants to merge 5 commits into
experimentalfrom
copilot/add-dropdown-field-assignment-settings

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 6, 2026

The implementation had unnecessary indirection through a hook_listener class (no Moodle hook exists for module form injection) and split event handling across two observer classes with no meaningful distinction.

Changes

  • lib.php — Form logic inlined directly into block_exaport_coursemodule_standard_elements(); no longer delegates to the removed hook_listener class
  • classes/observer.phpcourse_module_created() and course_module_updated() merged in from the now-deleted event_observer.php; all event handling lives in one place
  • db/events.php — Course module event callbacks updated to reference \block_exaport\observer instead of \block_exaport\event_observer

Deleted

File Reason
classes/hook_listener.php Unnecessary wrapper; logic now lives directly in lib.php
classes/event_observer.php No reason to split from observer.php; same namespace, same pattern
db/hooks.php Was entirely empty ($callbacks = [])
Original prompt

Objective

Implement a modern Moodle 5 hook callback to extend the assignment activity settings page with a dropdown field. This should be done in a Moodle-conform way using the hooks API.

Requirements

1. Create Hook Listener Class

Create blocks/exaport/classes/hook_listener.php with:

  • A static method that handles the \core\hook\form_coursemodule_standard_elements hook
  • Only apply to assignment activities (check $hook->get_cmtype() === 'assign')
  • Add a dropdown (select element) with the following options:
    • testvalue1
    • testvalue2
    • testvalue3
  • Field name should be: block_exaport_assignment_option
  • Use proper namespace: block_exaport\hook_listener

2. Register Hook

Create blocks/exaport/db/hooks.php to register the hook callback:

  • Follow Moodle 5 hooks registration format
  • Register the \core\hook\form_coursemodule_standard_elements hook

3. Add Language Strings

Add to blocks/exaport/lang/en/block_exaport.php (or create if needed):

  • $string['assignment_option'] = 'Exaport Assignment Option';
  • $string['testvalue1'] = 'Test Value 1';
  • $string['testvalue2'] = 'Test Value 2';
  • $string['testvalue3'] = 'Test Value 3';

4. Add Placeholder Event Observers (for future development)

Create blocks/exaport/classes/event_observer.php with placeholder methods:

  • public static function course_module_created(\core\event\course_module_created $event) - placeholder for saving data when assignment is created
  • public static function course_module_updated(\core\event\course_module_updated $event) - placeholder for saving data when assignment is updated

Register observers in blocks/exaport/db/events.php:

  • Listen to \core\event\course_module_created
  • Listen to \core\event\course_module_updated

5. Code Structure Requirements

  • Follow Moodle coding standards
  • Use proper type hints (PHP 7.4+ style with : void return types)
  • Add PHPDoc comments
  • Use defined('MOODLE_INTERNAL') || die(); where appropriate
  • The code should NOT actually save/load data yet - just show the dropdown and have TODO comments in the event observers

Implementation Notes

  • This is a skeleton implementation for step-by-step development
  • The dropdown should appear in the assignment settings form
  • Data persistence will be implemented later
  • All code should be production-ready in terms of structure and style, just with dummy/placeholder functionality

Expected Files to Create/Modify

  1. blocks/exaport/classes/hook_listener.php (new)
  2. blocks/exaport/db/hooks.php (new)
  3. blocks/exaport/classes/event_observer.php (new)
  4. blocks/exaport/db/events.php (new or modify)
  5. blocks/exaport/lang/en/block_exaport.php (modify - add strings)

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: richardwolfmayr <24298463+richardwolfmayr@users.noreply.github.com>
Copilot AI changed the title [WIP] Add dropdown field to assignment activity settings Add Moodle 5 hook integration: assignment settings dropdown via hooks API Mar 6, 2026
…of non-existent hook

Co-authored-by: richardwolfmayr <24298463+richardwolfmayr@users.noreply.github.com>
Copilot AI changed the title Add Moodle 5 hook integration: assignment settings dropdown via hooks API Replace non-existent hook with real Moodle coursemodule_standard_elements callback Mar 6, 2026
Copilot AI changed the title Replace non-existent hook with real Moodle coursemodule_standard_elements callback Replace non-existent Moodle hook with correct coursemodule_standard_elements callback Mar 6, 2026
…into observer, remove hook/indirection files

Co-authored-by: richardwolfmayr <24298463+richardwolfmayr@users.noreply.github.com>
Copilot AI changed the title Replace non-existent Moodle hook with correct coursemodule_standard_elements callback Cleanup: inline coursemodule_standard_elements, merge event_observer into observer Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants