Hi guys
I’m implementing my first 5.2 plugin and I’m trying to use services.xml to define my subscribers, but I’m having some issues on Subscriber considering the implementation I used before 5.2.
Before we had Bootstrap file and we could have this:
/**
* Registers all necessary events and hooks.
*/
public function subscribeEvents()
{
$this->subscribeEvent('Enlight_Controller_Front_DispatchLoopStartup', 'onStartDispatch');
}
/**
* Create Subscribers
*
* @param Enlight_Event_EventArgs $args
*/
public function onStartDispatch(\Enlight_Event_EventArgs $args)
{
$this->Application()->Events()->addSubscriber(new Subscribers\Backend($this));
$this->Application()->Events()->addSubscriber(new Subscribers\Frontend($this));
}
This was a way to load subscribers dynamically. And an example of my old Backend subscriber:
bootstrap = $bootstrap;
}
public static function getSubscribedEvents()
{
return array(
'Enlight_Controller_Action_PostDispatchSecure_Backend_Article' => array(
'onArticlePostDispatch'
)
);
}
public function onArticlePostDispatch(Enlight_Event_EventArgs $args)
{
/** @var \Enlight_Controller_Action $controller */
$controller = $args->getSubject();
$view = $controller->View();
$request = $controller->Request();
$view->addTemplateDir($this->bootstrap->Path() . '/Views');
$this->bootstrap->Application()->Snippets()->addConfigDir(
$this->bootstrap->Path() . 'Snippets/'
);
if ($request->getActionName() === 'load') {
$args->getSubject()->View()->extendsTemplate('backend/my_plugin/model/attribute.js');
}
}
}
So, on subscriber we had access to Bootrap context so we could access Path(), Application(), etc.
My question is how can I access this vars using the recomended 5.2 Plugin System. Defining the subscriber on services.xml and without Bootstrap I can’t access Path() neither other stuff we need on Subscribers, like adding snippets as I show on example above.
Thanks for help.
Best
Carlos