Repository navigation
feat(core): before/after Symfony events around publish, discard, block save and delete - #60
Merged
Merged
Conversation
…k save and delete A cache purge or a webhook meant decorating ContentAreaPublisherInterface, a block save had no hook, and nothing could stop an action. Eight events in ContentBlocks\Event, in before/after pairs. A "before" event is refusable: RefusableEvent::refuse() collects a reason and every listener still runs. A refused action writes nothing, and the builder says why: in the snackbar for publish, discard and delete (a 409 with error "refused"), above the form for a block save. A PHP caller of the publisher gets an ActionRefusedException. "After" events follow the flush. The area events come from EventDispatchingPublisher, the outermost decorator of the publisher interface: "before" runs ahead of the i18n and host decorators, "after" once they have committed, and a replaced publisher still dispatches. The block events come from the sidebar form and the delete action only; they are draft events. The sandbox's E2eRefusalListener refuses what the cb_e2e_refuse cookie names, pinned by event-refusal.spec.js. The README decorator example, which used the pre-1.0 signature, now shows a listener. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First item of the post-1.0 roadmap. Hosts can now follow and stop the four main editor actions with plain Symfony listeners, instead of decorating
ContentAreaPublisherInterface.BeforeContentAreaPublishEventAfterContentAreaPublishEventarea,contextBeforeContentAreaDiscardEventAfterContentAreaDiscardEventarea,contextBeforeBlockSaveEventAfterBlockSaveEventblock,area(+dataon before)BeforeBlockDeleteEventAfterBlockDeleteEventblock,areaRefusing an action
Every before event extends
RefusableEvent:$event->refuse('Why.')collects a reason, and every listener still runs so each can add its own. A refused action writes nothing (no draft change, no undo step, no after event):409 {"error": "refused", "message", "reasons"}and the builder shows the reason in its snackbar;ActionRefusedException.Reasons are shown as is (the host translates them).
BeforeBlockSaveEvent::$datais read-only: the block form stays the only whitelist.Where they are dispatched
EventDispatchingPublisher, the outermost decorator of the publisher interface (priority -1024): before runs ahead of the i18n and host decorators, after once they have committed, and a replaced publisher still dispatches.PublisherDecorationOrderTestpins the chain.BlockComponent::persistDraft()andBlocksController::delete()only. They are draft events; paste, templates, import, undo and section deletes do not dispatch them (the publish event still covers what they write).Compatibility
Additive: no interface method added, nothing changes for a host that listens to nothing, no migration. The publish/discard routes gain a
409answer, documented on the BC page.scripts/bc-check/run.shreports no break on the three packages.Also
PublishContext); it now shows a listener, and a correct decorator.App\EventListener\E2eRefusalListenerrefuses what thecb_e2e_refusecookie names (debug only).Test plan
event-refusal.spec.js(refused publish, delete, block save + recovery)🤖 Generated with Claude Code