Generic Event is empty when cherry-picking custom layouts


#1

Hello,

I am following this tutorial to show custom layouts based on object data
https://pimcore.com/docs/5.x/Development_Documentation/Best_Practice/Showing_Custom_Layouts_based_on_Object_Data.html
But I am getting an empty Data Structure of $event.
Could anyone help me where I am getting it wrong?

  <?php
    namespace AppBundle\EventListener;

    use Pimcore\Event\Model\ElementEventInterface;
    use Symfony\Component\EventDispatcher\GenericEvent;

    class LayoutListener {

        public function selectCustomLayout(GenericEvent $event) {

            \Pimcore\Log\Simple::log("loggy", json_encode($event));   // Output as {}
            $object = $event->getArgument("object");
            \Pimcore\Log\Simple::log("loggy", json_encode($object));  // Empty Output
            if($object instanceof Product) {

                //get product hierarchy level
                $hierarchyLevel = $object->getTypo(); 
                \Pimcore\Log\Simple::log("loggy", $hierarchyLevel);
                
                //data element that is send to Pimcore backend UI
                $data = $event->getArgument("data");
                \Pimcore\Log\Simple::log("loggy", json_encode($data));

                switch ($hierarchyLevel) {
                    case "product":
                    $data = $this->doModifyCustomLayouts($data, null, [12,13,15,16,18,20,22,23]);
                    break;
                    case "color":
                    $data = $this->doModifyCustomLayouts($data, null, [10,13,14,16,17,20,21,23]);
                    break;
                }
                
                $event->setArgument("data", $data);
                \Pimcore\Log\Simple::log("loggy", json_encode($data));
            }

        }
       

    }

Thanks in Advance.
Regards,
Akansh