Problem/Motivation
Child of #3624396: Plan: Harden InstanceInterface, IslandInterface and DisplayBuildableInterface as public API before RC1. Three names leave the module's namespace or its conventions, and get expensive once 1.0 ships:
hook_island_info_alter(). Hooks share one namespace, and drupal.org has a project namedisland, whose hooks arehook_island_*.plugin.manager.db_island, the one service ID with an abbreviation, where "db" reads as database.- The other service IDs are strings,
display_builder.*and their submodule equivalents. Core gives services their class name as ID, and keeps string IDs for plugin managers only. - The 11 builder events are named
onUpdate,onAttachToRootand so on: event names are global, and core prefixes them with the module. Their docblocks also promise more than happens: "Fired when a new node is attached directly at root level", while they fire only from the builder UI, never for a change made throughInstanceInterface.
Proposed resolution
hook_island_info_alter()becomeshook_display_builder_island_info_alter().plugin.manager.db_islandbecomesplugin.manager.display_builder_island.plugin.manager.display_buildablestays: it already follows the convention, and the instance'sbuildablefield stores it.- Every other service of the module and its submodules takes its class name as ID. The existing class name aliases become the IDs.
- The discovery cache key
island_pluginsbecomesdisplay_builder_island_plugins. - No deprecated alias. The known users, UI Controls and
display_builder_ai, change and release at the same time, and require the release that renames. - Document the renamed hook in
display_builder.api.php, as #3627266: Mark the API boundary: @api on what contrib extends, @internal on the rest plans for both alter hooks. - The values of the 11
DisplayBuilderEventsconstants take the module prefix:display_builder.update,display_builder.attach_to_root,display_builder.attach_to_slot,display_builder.move,display_builder.active,display_builder.delete,display_builder.history_change,display_builder.restore,display_builder.revert,display_builder.publish,display_builder.preset_save. The constant names stay, so a subscriber using them is unaffected. No code relies on the values: the island fan-out maps each constant to a method of its own. - Their docblocks say what they are: builder UI events, fired by the builder after an action, carrying the islands' updates back to the browser. One line on the class: a change made through
InstanceInterfaceoutside the builder fires none of them.
Remaining tasks
- Update UI Controls:
IslandInfoHooksandStylesIslandTest. - Update
display_builder_ai:AddComponentandSetLayout. - Write the change record.
User interface changes
None.
API changes
hook_island_info_alter()renamedhook_display_builder_island_info_alter().plugin.manager.db_islandrenamedplugin.manager.display_builder_island.- Service IDs
display_builder.*,display_builder_entity_view.*,display_builder_page_layout.*anddisplay_builder_views.*replaced by class names. DisplayBuilderEventsvalues prefixed withdisplay_builder., constant names unchanged.
Data model changes
None. The island discovery cache rebuilds under its new key.
Issue fork display_builder-3627272
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 #2
mogtofu33 commentedComment #3
mogtofu33 commentedComment #4
pdureau commentedThis island project is a placeholder to host a shared implementation of the island & profile mechanism between many projects. Already 2 teams has expressed their interest for using the islands system of their upcoming contrib projects (a kanban board and a task manager), it will be discussed in DrupalCamp Germany later this year.
So I guess we would want to share the namespace.
Renaming the services with namespaced class names is already the goal of #3613447: More autowire for plugins DI, but the codebase was moving too much, so postponed until we stabilized it.
Indeed, Core prefixes services with the module name (most of the time):
👌Let's do the change.
Comment #6
pdureau commentedEvents renamed.
Comment #7
csakiistvanComment #8
csakiistvan✅ Tested and works — applied MR !511, rebuilt caches and listed the
DisplayBuilderEventsvalues with their listeners: all 11 now carry thedisplay_builder.prefix and each keeps its listeners, andApiControllerTest,IslandEventTestandPresetMessagesSubscriberTestpass. I pushed the missing class docblock line (builder UI events, none fired for changes made throughInstanceInterface), so this needs another reviewer.Notes
'onUpdate'-style strings in the module are subscriber method names, so nothing depends on the old values.islandnamespace, services moved to #3613447); the IS could be updated to match.Comment #9
pdureau commentedComment #10
mogtofu33 commentedLittle doc fix added, thanks.
Comment #13
pdureau commentedShipped in beta10 release.