Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions with multiple navigations in config #3

Open
av3 opened this issue Aug 19, 2018 · 3 comments
Open

Exceptions with multiple navigations in config #3

av3 opened this issue Aug 19, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@av3
Copy link

av3 commented Aug 19, 2018

Hello froschdesign,

currently I have a project where I use the "old" https://github.com/froschdesign/zend-navigation/tree/feature/expressive-support for using Zend-Navigation with multiple navigations in Expressive.

Because I wanted to switch to Zend Expressive 3 (which isn't compatible to the old branch), I wanted to switch to this zend-expressive-navigation and already tested the newest version with your quickstart description.

If I have only one "default" key in my configuration array, everything works fine. But if I add a "footer" key (with an empty array, without pages), I get an error message (also without trying to call the view helper for that navigation):

Zend \ ServiceManager \ Exception \ ServiceNotCreatedException

Service with name "Zend\Navigation\Footer" could not be created. Reason: Invalid argument: Unable to determine class to instantiate

In my ConfigAggregator I have

    \Zend\Navigation\ZendView\ConfigProvider::class,
    \Zend\Expressive\Navigation\ConfigProvider::class,

This was the first error without any pages; if the default key has an empty array as value, there is no error, just an empty navigation output.

Then I added a page to my footer array. Example:

            'default' => [
                [

                    'type' => \Zend\Expressive\Navigation\Page\ExpressivePage::class,
                    'label' => 'Startseite',
                    'route' => 'home',
                ]
            ],
            'footer' => [
                [

                    'type' => \Zend\Expressive\Navigation\Page\ExpressivePage::class,
                    'label' => 'Startseite',
                    'route' => 'home',
                ]
            ]

No I get the another exception:

Whoops \ Exception \ ErrorException (E_ERROR)
Method Zend\View\Helper\Navigation\Menu::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Zend\Expressive\Helper\UrlHelper::setRouteResult() must be an instance of Zend\Expressive\Router\RouteResult, null given, called in /application/vendor/zendframework/zend-expressive-navigation/src/Page/ExpressivePage.php on line 92

@froschdesign
Copy link
Owner

Right, this is a bug. A workaround:

  • remove the config-provider for this component
  • add manually the dependencies:
'abstract_factories' => [
    \Zend\Expressive\Navigation\Service\ExpressiveNavigationAbstractServiceFactory::class,
],
'aliases'            => [
    'navigation' => \Zend\Navigation\Navigation::class,
],
'factories'          => [
    Zend\Expressive\Navigation\Middleware\NavigationMiddleware::class => Zend\Expressive\Navigation\Middleware\NavigationMiddlewareFactory::class,
],

(without the factory ExpressiveNavigationFactory)

@froschdesign froschdesign self-assigned this Aug 19, 2018
@av3
Copy link
Author

av3 commented Aug 19, 2018

Thank you! Then I have to use Zend\Navigation\Footer for the view helper (even if I use 'footer' with a small f for the key) and I'm getting my footer navigation. :)

@froschdesign froschdesign added this to the 0.1 milestone Oct 9, 2018
@froschdesign
Copy link
Owner

The current idea is to remove the ExpressiveNavigationFactory because the abstract factory (ExpressiveNavigationAbstractServiceFactory) can do all the work with the same result.

I have already written some unit tests but some tests in an application are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants