In order to integrate #2844054: Inline Revisionable Content Blocks with Panels IPE and Page Manager, both of which make use of BlockVariantTrait, modules will need to be able to react to changes in the variant. Therefore, BlockVariantTrait should fire events when a block is added, modified, or removed.

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

Status: Active » Needs review
Issue tags: +Needs tests
Related issues: +#2844054: Inline Revisionable Content Blocks
StatusFileSize
new6.35 KB
phenaproxima’s picture

Issue tags: -Needs tests
StatusFileSize
new9.5 KB

Wrote a basic kernel test to prove that events are fired.

Status: Needs review » Needs work

The last submitted patch, 3: 2883103-3.patch, failed testing.

phenaproxima’s picture

Status: Needs work » Needs review
StatusFileSize
new9.6 KB

Whoops.

phenaproxima’s picture

Filed an initial patch against Panels to load inline blocks out of tempstore: #2883154: Support inline blocks in Panels display variants.

tim.plunkett’s picture

+++ b/src/Plugin/BlockVariantTrait.php
@@ -39,6 +49,11 @@ trait BlockVariantTrait {
     $this->getBlockCollection()->addInstanceId($configuration['uuid'], $configuration);
...
+    $event = new BlockVariantEvent($block, $this);
+    $this->eventDispatcher()->dispatch(BlockVariantEvents::ADD_BLOCK, $event);

@@ -54,8 +72,11 @@ trait BlockVariantTrait {
     $this->getBlockCollection()->setInstanceConfiguration($block_id, $configuration + $existing_configuration);
+    $event = new BlockVariantEvent($block, $this);
+    $this->eventDispatcher()->dispatch(BlockVariantEvents::UPDATE_BLOCK, $event);

It seems to me the event should happen before the configuration is set, so that it could be manipulated? Or do we need to wait to get a full block to pass around

phenaproxima’s picture

StatusFileSize
new9.75 KB
new1.36 KB

I am in favor of firing these events after the main event has occurred. If there is a chance that the blocks are not completely coherent by the time the event is fired, the event subscribers may encounter serious WTFs, and that would be terrible DX. So, after is the way to go, I think.

Just a few very minor changes...

eclipsegc’s picture

Status: Needs review » Fixed

Committed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.