2017 © Pedro Peláez
 

library navigation-bundle

image

webfactory/navigation-bundle

  • Wednesday, June 20, 2018
  • by webfactory
  • Repository
  • 8 Watchers
  • 2 Stars
  • 1,067 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 54 Versions
  • 18 % Grown

The README.md

WebfactoryNavigationBundle

Symfony Bundle featuring:, (*1)

  • A factory for creating the navigation tree, using BuildDirectors which you can add to, if needed
  • Twig functions for rendering navigation elements (tree, ancestry, breadcrumbs) and inspecting the navigation tree

Installation

composer require webfactory/navigation-bundle 

... and activate the bundle in your kernel, depending on your Symfony version., (*2)

Rendering navigation elements in Twig

Simple Navigation List

Syntax

{{ navigation_tree(root, maxLevels = 1, expandedLevel = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}

Examples

{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}) }}

{{ navigation_tree(
  root = {"webfactory_pages.page_id": root_page_id, "_locale": app.request.locale},
  template = 'AppBundle:Navigation:navigation.html.twig'
) }}

Ancestry List

An ancestry list is the active path from the given start level to the currently active node. Useful if you want to render e.g. the third level navigation outside of the regular navigation., (*3)

Syntax

{{ navigation_ancestry(startLevel, maxLevels = 1, expandedLevels = 1, template = '@WebfactoryNavigation/Navigation/navigation.html.twig') }}

Examples

{{ navigation_ancestry(startLevel = 1) }}

{{ navigation_ancestry(startLevel = 1, template = '@App/Navigation/secondaryNav.html.twig') }}

Syntax

{{ navigation_breadcrumbs(template = '@WebfactoryNavigation/Navigation/breadcrumbs.html.twig') }}

Examples

{{ navigation_breadcrumbs() }}
{{ navigation_breadcrumbs(template = '@App/Navigation/breadcrumbs.html.twig') }}

Customisation

For each function mentioned above you can provide a Twig template in which you can extend the base template and overwrite each block. Please find the default blocks in src/Resources/views/Navigation/navigationBlocks.html.twig., (*4)

Example:, (*5)

{# layout.html.twig: #}

...
{{ navigation_tree(root = {"webfactory_pages.page_id": root_page_id}, template = 'AppBundle:Navigation:navigation.html.twig') }}
...
{# AppBundle:Navigation:navigation.html.twig: #}

{% extends "@WebfactoryNavigation/Navigation/navigation.html.twig" %}

{% block navigation_list %}
    <nav class="project-specific-classes">
        {{ parent() }}
    </nav>
{% endblock %}

Modifying the NavigationTree

Implement a Webfactory\Bundle\NavigationBundle\Build\BuildDirector. Example:, (*6)

<?php

namespace AppBundle\Navigation;

use JMS\ObjectRouting\ObjectRouter;
use Symfony\Component\Config\Resource\FileResource;
use Webfactory\Bundle\NavigationBundle\Build\BuildContext;
use Webfactory\Bundle\NavigationBundle\Build\BuildDirector;
use Webfactory\Bundle\NavigationBundle\Build\BuildDispatcher;
use Webfactory\Bundle\NavigationBundle\Tree\Tree;
use Webfactory\Bundle\WfdMetaBundle\Config\DoctrineEntityClassResource;

final class KeyActionBuildDirector implements BuildDirector
{
    /** @var YourEntityRepository */
    private $repository;

    /** @var ObjectRouter */
    private $objectRouter;

    public function __construct(YourEntityRepository $repository, ObjectRouter $objectRouter)
    {
        $this->repository = $repository;
        $this->objectRouter = $objectRouter;
    }

    public function build(BuildContext $context, Tree $tree, BuildDispatcher $dispatcher): void
    {
        if (!$this->isInterestedInContext($context)) {
            return;
        }

        foreach ($this->repository->findForMenu() as $entity) {
            $context->get('node')
                ->addChild()
                ->set('caption', $entity->getName())
                ->set('visible', true)
                ->set('url', $this->objectRouter->path('detail', $entity));
        }

        $this->addResourcesToTreeCache($dispatcher);
    }

    private function addResourcesToTreeCache(BuildDispatcher $dispatcher): void
    {
        $dispatcher->addResource(new FileResource(__FILE__));
        $dispatcher->addResource(new DoctrineEntityClassResource(YourEntity::class));
    }
}

Define your implementation as a service and tag it webfactory_navigation.build_director. Example:, (*7)

<service class="AppBundle\Navigation\YouEntityBuildDirector">
    <argument type="service" id="AppBundle\Repository\YourEntityRepository" />
    <argument type="service" id="JMS\ObjectRouting\ObjectRouter" />
    <tag name="webfactory_navigation.build_director"/>
</service>

See src/Resources/doc/How-To-Use-Klassendiagramm.puml for more., (*8)

This project was started at webfactory GmbH, Bonn., (*9)

Copyright 2015 - 2021 webfactory GmbH, Bonn. Code released under the MIT license., (*10)

The Versions

20/06 2018

dev-master

9999999-dev

  Sources   Download

The Requires

 

20/06 2018
14/07 2017

3.1.0

3.1.0.0

  Sources   Download

The Requires

 

15/05 2017

3.0.0

3.0.0.0

  Sources   Download

The Requires

 

04/07 2016
10/05 2016

1.0.x-dev

1.0.9999999.9999999-dev

  Sources   Download

The Requires

 

10/05 2016

1.0.21

1.0.21.0

  Sources   Download

The Requires

 

11/02 2015

2.2.4

2.2.4.0

  Sources   Download

The Requires

 

03/02 2015

2.2.3

2.2.3.0

  Sources   Download

The Requires

 

04/08 2014

2.2.2

2.2.2.0

  Sources   Download

The Requires

 

07/07 2014

2.2.1

2.2.1.0

  Sources   Download

The Requires

 

10/12 2013

2.2.0

2.2.0.0

  Sources   Download

The Requires

 

05/12 2013

2.1.0

2.1.0.0

  Sources   Download

The Requires

 

01/02 2013

2.0.1

2.0.1.0

  Sources   Download

The Requires

 

29/10 2012

1.1.6

1.1.6.0

  Sources   Download

The Requires

 

22/10 2012

1.1.5

1.1.5.0

  Sources   Download

The Requires

 

19/10 2012

1.1.4

1.1.4.0

  Sources   Download

The Requires

 

19/10 2012

1.1.3

1.1.3.0

  Sources   Download

The Requires

 

23/08 2012

1.1.2

1.1.2.0

  Sources   Download

The Requires

 

25/07 2012

1.0.20

1.0.20.0

  Sources   Download

The Requires

 

25/07 2012

1.1.1

1.1.1.0

  Sources   Download

The Requires

 

24/07 2012

1.1.0

1.1.0.0

  Sources   Download

The Requires

 

24/07 2012

1.0.19

1.0.19.0

  Sources   Download

The Requires

 

20/07 2012

1.0.18

1.0.18.0

  Sources   Download

The Requires

 

16/07 2012

1.0.17

1.0.17.0

  Sources   Download

The Requires

 

09/07 2012

1.0.16

1.0.16.0

  Sources   Download

The Requires

 

06/07 2012

1.0.15

1.0.15.0

  Sources   Download

The Requires

 

06/07 2012

1.0.14

1.0.14.0

  Sources   Download

The Requires

 

05/07 2012

1.0.13

1.0.13.0

  Sources   Download

The Requires

 

05/07 2012

1.0.12

1.0.12.0

  Sources   Download

The Requires

 

05/07 2012

1.0.11

1.0.11.0

  Sources   Download

The Requires

 

04/07 2012

1.0.10

1.0.10.0

  Sources   Download

The Requires

 

22/02 2012

1.0.9

1.0.9.0

  Sources   Download

The Requires

 

22/02 2012

1.0.8

1.0.8.0

  Sources   Download

The Requires

 

21/02 2012

1.0.7

1.0.7.0

  Sources   Download

The Requires

 

20/12 2011

1.0.6

1.0.6.0

  Sources   Download

The Requires

 

20/12 2011

1.0.5

1.0.5.0

  Sources   Download

The Requires

 

20/12 2011

1.0.4

1.0.4.0

  Sources   Download

The Requires

 

20/12 2011

1.0.3

1.0.3.0

  Sources   Download

The Requires

 

20/12 2011

1.0.2

1.0.2.0

  Sources   Download

The Requires

 

20/12 2011

1.0.1

1.0.1.0

  Sources   Download

The Requires

 

20/12 2011

1.0.0

1.0.0.0

  Sources   Download

The Requires