Oro plaform is flexible system which give ability to customize CRUD page in admin for example you can add a custom section to edit order page and add new form or show custom details .
Let’s start by adding you service :
ibnab_customsection_order.event_listener.order_edit_view_listener: class: 'Ibnab\Bundle\CustomSectionBundle\EventListener\OrderEditViewListener' arguments: - '@translator' tags: - { name: kernel.event_listener, event: oro_ui.scroll_data.before.order-edit, method: onEdit }
Here we handle kernel.event_listener of type oro_ui.scroll_data.before.order-edit to observe and inject of custom section to edit order page by the method onEdit ,
The content of our class which contain onEdit function:
<?php namespace Ibnab\Bundle\CustomSectionBundle\EventListener; use Oro\Bundle\UIBundle\Event\BeforeListRenderEvent; use Symfony\Contracts\Translation\TranslatorInterface; use Oro\Bundle\UIBundle\View\ScrollData; class OrderEditViewListener { const CUSTOMSECTION_BLOCK_ID = 'customsection'; /** @var int */ const BLOCK_PRIORITY = 100; /** * @var TranslatorInterface */ protected $translator; /** * @param TranslatorInterface $translator */ public function __construct(TranslatorInterface $translator) { $this->translator = $translator; } /** * @param BeforeListRenderEvent $event */ public function onEdit(BeforeListRenderEvent $event) { $entity = $event->getEntity(); if ($entity != '''') { $template = $event->getEnvironment()->render( 'IbnabCustomSectionBundle:Order:update_order.html.twig', ['entity' => $entity,'form' => $event->getFormView()] ); $this->addCustomSectionBlock($event->getScrollData(), $template); } } /** * @param ScrollData $scrollData * @param string $template */ private function addCustomSectionBlock(ScrollData $scrollData, $template) { $scrollData->addNamedBlock(self::CUSTOMSECTION_BLOCK_ID, $this->translator->trans('ibnab.customsection.order.sections.customsection.label'), self::BLOCK_PRIORITY); $subBlock = $scrollData->addSubBlock(self::CUSTOMSECTION_BLOCK_ID); $scrollData->addSubBlockData(self:: CUSTOMSECTION_BLOCK_ID $subBlock, $template, self::CUSTOMSECTION_BLOCK_ID); } }
You can explore onEdit function which receive as param $event of type Oro\Bundle\UIBundle\Event\BeforeListRenderEvent which give you ability for example to get current entity by $event->getEntity(); or form by $event->getForm(); so in this section we will render a twig IbnabCustomSectionBundle:Order:update_order.html.twig and pass to variables $entity and $form, and we finish by call internal method of class addCustomSectionBlock to add block section with method addNamedBlock of object ScrollData $scrollData , the I of block is self::CUSTOMSECTION_BLOCK_ID and has a label for tab , after that we add a subBlock = content of block with same id and the result of twig $template .
let’s add our twig template IbnabCustomSectionBundle:Order:update_order.html.twig the full path is Ibnab/Bundle/CustomSectionBundle/Resources/views/Order/ update_order.html.twig an for example the content is :
{{ form_row(form.paymentDate) }}
for example you custom field paymentDate whicch get added by migration and from and you can manage save value by form extension
Comments