Skip to content

Commit

Permalink
fixed inability to override view helper instructions before render event
Browse files Browse the repository at this point in the history
  • Loading branch information
hummer2k committed Oct 17, 2015
1 parent e63bce5 commit e8d8d0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion config/con-layout.global.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ return [
'proxy' => HeadTitleProxy::class
],
'headMeta' => [
'method' => 'appendName',
'method' => 'setName',
'default_param' => 'name',
'proxy' => HeadMetaProxy::class
],
Expand Down
40 changes: 26 additions & 14 deletions src/ConLayout/Listener/ViewHelperListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Zend\EventManager\ListenerAggregateTrait;
use Zend\Filter\FilterInterface;
use Zend\Filter\FilterPluginManager;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ArrayUtils;
use Zend\View\HelperPluginManager;

Expand All @@ -31,13 +32,13 @@ class ViewHelperListener implements ListenerAggregateInterface
*
* @var LayoutUpdaterInterface
*/
protected $updater;
private $updater;

/**
*
* @var HelperPluginManager
*/
protected $viewHelperManager;
private $viewHelperManager;

/**
*
Expand All @@ -49,7 +50,13 @@ class ViewHelperListener implements ListenerAggregateInterface
*
* @var array
*/
protected $helperConfig = [];
private $helperConfig = [];

/**
*
* @var boolean
*/
private $isLoaded = false;

/**
*
Expand All @@ -75,21 +82,26 @@ public function __construct(
*/
public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->getSharedManager()
->attach(
Layout::class,
'load.pre',
[$this, 'applyViewHelpers']
);
$this->listeners[] = $events->attach(
MvcEvent::EVENT_DISPATCH,
[$this, 'applyViewHelpers'],
100
);
$this->listeners[] = $events->getSharedManager()->attach(
Layout::class,
'load.pre',
[$this, 'applyViewHelpers']
);
}

/**
* applies view helpers
*
* @return LayoutModifierListener
* applies view helper instructions
*/
public function applyViewHelpers()
public function applyViewHelpers($e)
{
if ($this->isLoaded) {
return;
}
$viewHelperInstructions = $this->updater->getLayoutStructure()->get(
LayoutUpdaterInterface::INSTRUCTION_VIEW_HELPERS
);
Expand Down Expand Up @@ -137,7 +149,7 @@ public function applyViewHelpers()
}
}
}
return $this;
$this->isLoaded = true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ConLayoutTest/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testOnBootstrapListenersWithHttpRequest()

$module->onBootstrap($event);

$this->assertCount(2, $em->getListeners(MvcEvent::EVENT_DISPATCH));
$this->assertCount(3, $em->getListeners(MvcEvent::EVENT_DISPATCH));

$layoutUpdater = $sm->get(LayoutUpdaterInterface::class);

Expand Down

0 comments on commit e8d8d0f

Please sign in to comment.