<?php
namespace App\EventListener\SonataAdmin\Block;
use App\Enum\Common\AdminCodesEnum;
use Sonata\BlockBundle\Event\BlockEvent;
use Sonata\BlockBundle\Model\Block;
final class EntityGeneralInfoBlock
{
public function onBlock(BlockEvent $event): void
{
$codes = [];
if (!($admin = $event->getSetting('admin'))) {
return;
}
$codes[$admin->getCode()] = true;
if ($admin->isChild() && ($parentAdmin = $admin->getParent())) {
$codes[$parentAdmin->getCode()] = true;
}
$blockType = null;
if (isset($codes[AdminCodesEnum::PDB_PRODUCT])) {
$blockType = 'app.block.product_general_info';
} elseif (isset($codes[AdminCodesEnum::TV_SALES_OFFER])) {
$blockType = 'app.block.tv_sales_offer_general_info';
} elseif (isset($codes[AdminCodesEnum::VOD_TITLE])) {
$blockType = 'app.block.vod.product_overview';
}
if (!is_null($blockType)) {
$block = new Block();
$block->setId(uniqid('', true));
$block->setSettings($event->getSettings());
$block->setType($blockType);
$event->addBlock($block);
}
}
}