Message-ID: <1717025109.2634.1485845835196.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_2633_1175807789.1485845835196" ------=_Part_2633_1175807789.1485845835196 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Legacy kernel event

Legacy kernel event

For better integration between 5.x (symfony based) kernel and le= gacy (4.x) kernel, injection is used to inject settings, session and current siteaccess from 5.x into legacy using an event: = ;kernel.event_subscriber

This page describe how you can do that.  

Adding a k= ernel.event_subscriber

A legacy kernel event subscriber is added by tagging your event subscrib= er service.

Bellow is an example of yml configuration involved:

kernel.event_subscriber
=20
    my_app.legacy_mapper.something:
        class: %my_app.legacy_mapper.something.class%
        arguments: [@service_container]
        tags:
            - { name: kernel.event_subscriber }
=20

 

The class refered to as %= my_app.legacy_mapper.something.class% can look like this:

my_app.legacy_mapper.something.class
=20
namespace MyApp\LegacyMapper;
use eZ\Publish\Core\MVC\Legacy\LegacyEvents;
use eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelWebHandlerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
 * Maps something into Legacy kernel
 */
class Something implements EventSubscriberInterface
{
    /**
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
     */
    private $container;
 
   /**
    * @param \Symfony\Component\DependencyInjection\ContainerInterface $con=
tainer
    */
    public function __construct( ContainerInterface $container )
    {
        $this->container =3D $container;
    }
    public static function getSubscribedEvents()
    {
        return array(
            LegacyEvents::PRE_BUILD_LEGACY_KERNEL_WEB =3D> array( 'onBui=
ldKernelWebHandler', 128 )
        );
    }
    /**
     * Maps matched siteaccess to the legacy parameters
     *
     * @param \eZ\Publish\Core\MVC\Legacy\Event\PreBuildKernelWebHandlerEve=
nt $event
     *
     * @return void
     */
    public function onBuildKernelWebHandler( PreBuildKernelWebHandlerEvent =
$event )
    {
        // Do something, see eZ\Bundle\EzPublishLegacyBundle\LegacyMapper\*=
 for examples
        // Example for injecting some settings:
 
        $settings =3D array(
            'site.ini/Block/Setting' =3D> $this->container->getPar=
ameter( 'some.setting' ),
            'site.ini/Block/Setting2' =3D> $this->configResolver->=
getParameter( 'some.setting2' )
        );
 
        $event->getParameters()->set(
            "injected-settings",
            $settings + (array)$event->getParameters()->get( "injecte=
d-settings" )
        );
    }
}

=20


------=_Part_2633_1175807789.1485845835196--