Skip to content

Instantly share code, notes, and snippets.

@skl
Created September 16, 2015 16:13
Show Gist options
  • Save skl/cbf4580fcbf546eb6fa2 to your computer and use it in GitHub Desktop.
Save skl/cbf4580fcbf546eb6fa2 to your computer and use it in GitHub Desktop.

Revisions

  1. skl created this gist Sep 16, 2015.
    42 changes: 42 additions & 0 deletions Module.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    <?php

    namespace Application;

    use Zend\ModuleManager\ModuleEvent;
    use Zend\ModuleManager\ModuleManager;

    /**
    * Class Module
    * @package Application
    */
    class Module
    {
    /**
    * @param ModuleManager $moduleManager
    */
    public function init(ModuleManager $moduleManager)
    {
    $events = $moduleManager->getEventManager();
    $events->attach(ModuleEvent::EVENT_MERGE_CONFIG, [$this, 'onMergeConfig']);
    }

    /**
    * @param ModuleEvent $e
    */
    public function onMergeConfig(ModuleEvent $e)
    {
    $configListener = $e->getConfigListener();
    $config = $configListener->getMergedConfig(false);

    // If both ZfcTwigViewStrategy and ViewJsonStrategy registered, prioritise ViewJsonStrategy, this fixes an issue
    // with the zfctwig module where it was trying to load layouts for JsonModel responses.
    if (isset($config['view_manager']['strategies'])
    && false !== array_search('ViewJsonStrategy', $config['view_manager']['strategies'])
    && false !== ($zfcKey = array_search('ZfcTwigViewStrategy', $config['view_manager']['strategies']))
    ) {
    unset($config['view_manager']['strategies'][$zfcKey]);
    array_push($config['view_manager']['strategies'], 'ZfcTwigViewStrategy');

    $configListener->setMergedConfig($config);
    }
    }