<?php
namespace App\Package\Block\Tools\ParentEntityUpdateSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use App\Package\Admin\Main\Event\EntityUpdateEvent;
/**
* ParentEntityUpdateSubscriber
*
* Subscriber which listens for parent entity update event (created or updated)
* - if parent entity has blocks then call dispatchEntityUpdateEvent
* for each one of blocks
*
* @author Daniel Balowski <d.balowski@openform.pl> (_creator)
* @copyright Openform
* @since 03.2019
*/
class ParentEntityUpdateSubscriber implements EventSubscriberInterface
{
/**
* @return array
*/
public static function getSubscribedEvents() : array
{
return [
EntityUpdateEvent::NAME => [
[ 'onEntityUpdate', 600 ],
]
];
}
/**
* On entity update event
*
* @param EntityUpdateEvent $event
*
* @return void
*/
public function onEntityUpdate(EntityUpdateEvent $event) : void
{
$updatedEntity = $event->getUpdatedEntity();
if (! method_exists($updatedEntity, 'getBlock')) {
return;
}
foreach($updatedEntity->getBlock() as $block) {
if (! method_exists($block, 'dispatchEntityUpdateEvent')) {
continue;
}
$block->dispatchEntityUpdateEvent();
}
return;
}
}