Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Zend\Navigation\Page\Mvc - IsActive Function "improvement ?" #53

Closed
@h3christophe

Description

@h3christophe

Hello
Right now to check if a Mvc Page is active you guys check if

$this->routeMatch->getMatchedRouteName() === $this->getRoute()

and that the parameters match

 (count(array_intersect_assoc($reqParams, $pageParams)) == count($pageParams)

I was wondering if we could improve this behavior by checking first if the Page route is actually contained in the Matched Route

Lets take an example:
Router conf:

'routes' => array(
            'production' => [
                'type' => 'segment',
                'may_terminate' => true,
                'options' => [
                    'route' => '/production',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Production\Controller',
                        'controller' => 'Index',
                        'action' => 'index'
                    )
                ],
                'child_routes' => [
                    'project' => [
                        'type' => 'segment',
                        'options' => [
                            'route' => '/project[/:action[/:id]]',
                            'defaults' => array(
                                'controller' => 'Project',
                                'action' => 'index'
                            )
                        ],
                    ],

This assume that the child route project is under production

so route "production/project" is a child of "production"

Navigation Conf:

 'navigation' => [
            'production' => [
                'id' => 'project',
                'label' => 'Production label',
                'route' => 'production'

The current isActive function does not work in this situation because the routes are different
The workaround it to create a child navigation under "production" but i feel like it is overkill (as i dont want to display the child page in the navigation (so i use the param visible = 0 ))

My solution would be to check that the page route is contained in the Matched route

strpos($this->routeMatch->getMatchedRouteName(), $this->getRoute().'/') === 0

In my scenario It would check if "production/" is contained in the "production/project" (at the beginning of the string)

And make the Page active

so if you are viewing the site via the "production/project" route it will make all navigation set up to use the route "production" active

Please let me know if that make sense or if I am missing something that would make this solution incorrect

Thank you

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions