8000 feat(core): before/after Symfony events around publish, discard, block save and delete by Klehm · Pull Request #60 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

feat(core): before/after Symfony events around publish, discard, block save and delete - #60

Merged
Klehm merged 1 commit into
masterfrom
feat/symfony-events
Sep 28, 2026
Merged

Klehm merged 1 commit into
masterfrom
feat/symfony-events

Conversation

@Klehm
@Klehm Klehm commented Sep 28, 2026
Copy link
Copy Markdown
Owner

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.

Action Before (refusable) After Properties
Publish BeforeContentAreaPublishEvent AfterContentAreaPublishEvent area, context
Revert to published BeforeContentAreaDiscardEvent AfterContentAreaDiscardEvent area, context
Save a block BeforeBlockSaveEvent AfterBlockSaveEvent block, area (+ data on before)
Delete a block BeforeBlockDeleteEvent AfterBlockDeleteEvent block, area

Refusing 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):

  • publish / discard / delete: the endpoint answers 409 {"error": "refused", "message", "reasons"} and the builder shows the reason in its snackbar;
  • block save: the reason is shown above the form, the typed value stays, and the next edit retries;
  • PHP callers of the publisher get an ActionRefusedException.

Reasons are shown as is (the host translates them). BeforeBlockSaveEvent::$data is read-only: the block form stays the only whitelist.

Where they are dispatched

  • The area events come from 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. PublisherDecorationOrderTest pins the chain.
  • The block events come from BlockComponent::persistDraft() and BlocksController::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 409 answer, documented on the BC page. scripts/bc-check/run.sh reports no break on the three packages.

Also

  • Guide page docs/guide/events.md, BC page, internals rationale, CHANGELOG, CLAUDE.md; the item leaves ROADMAP.md.
  • The README's publisher-decorator example used the pre-1.0 signature (no PublishContext); it now shows a listener, and a correct decorator.
  • Sandbox: App\EventListener\E2eRefusalListener refuses what the cb_e2e_refuse cookie names (debug only).

Test plan

  • PHPUnit: core 1058, i18n 183, kit 335
  • Vitest: core 505, i18n 28, kit 64
  • PHPStan level 8, php-cs-fixer
  • Playwright main suite: 198 passed, incl. the new event-refusal.spec.js (refused publish, delete, block save + recovery)
  • Playwright Encore suite: 7 passed
  • Docs build, internal links check
  • BC check against v1.1.0: no break

🤖 Generated with Claude Code

…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>
@Klehm
Klehm merged commit 1adac17 into master Sep 28, 2026
36 checks passed
@Klehm
Klehm deleted the feat/symfony-events branch September 28, 2026 12:25
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.

1 participant

0