Loading
🤖 Add hook_canvas_content_operation() so modules can add operations to Canvas content
Closes #3592132 (closed)
Adds hook_canvas_content_operation(), the Canvas counterpart of hook_entity_operation(). Modules return operations (title, url, optional weight).
ApiContentControllers::getEntityOperations()adds the operations the current user can access to the content links.- The content API exposes their labels in an optional
linkLabelsobject, in weight order. Responses without module operations are unchanged. - The pages panel and the page navigation menu render them as links, between Canvas's own operations and "Delete page".
A new hook is used instead of hook_entity_operation(), so Canvas controls which operations appear in its UI.
Use case: canvas_translate #3623308 adds a "Translate" operation.
Testing
-
ApiContentControllersListTest::testModuleProvidedOperations()passes. -
ui/src/utils/contentOperations.test.tspasses. - Enable a module implementing the hook (see
canvas.api.php). The operations appear in the pages panel and in the page navigation menu, in weight order, before "Delete page". - An operation whose URL the user cannot access is not shown.
- Without such a module, both menus are unchanged.
AI-discloure: Partially (Claude Code wrote the code and tests; reviewed and tested manually by the author.)
Closes #3592132 (closed)