webfactory / navigation-bundle
Installs: 17 963
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 8
Forks: 1
Open Issues: 1
Requires
- php: ^7.2|8.0.*|8.1.*|8.2.*|8.3.*
- ext-json: *
- psr/container: ^1.0
- psr/log: ^1.1|^2.0|^3.0
- symfony/config: ^4.0|^5.0|^6.0|^7.0
- symfony/console: ^4.0|^5.0|^6.0|^7.0
- symfony/dependency-injection: ^4.2|^5.0|^6.0|^7.0
- symfony/event-dispatcher: ^4.3|^5.0|^6.0|^7.0
- symfony/event-dispatcher-contracts: ^1.0|^2.0|^3.0
- symfony/http-foundation: ^5.3|^6.0|^7.0
- symfony/http-kernel: ^4.0|^5.0|^6.0|^7.0
- symfony/proxy-manager-bridge: ^4.0|^5.0|^6.0|^7.0
- symfony/service-contracts: ^1.0|^2.0|^3.0
- twig/twig: ^1.36|^2.6|^3.0
Requires (Dev)
- symfony/stopwatch: ^5.4|^6.0|^7.0
Suggests
- ocramius/proxy-manager: damit der NavigationTree wirklich lazy erzeugt wird
- symfony/stopwatch: um zu messen, wie lange der Aufbau des NavigationTree dauert
- dev-master
- 5.8.2
- 5.8.1
- 5.8.0
- 5.7.0
- 5.6.0
- 5.5.0
- 5.4.4
- 5.4.3
- 5.4.2
- 5.4.1
- 5.4.0
- 5.3.0
- 5.2.0
- 5.1.0
- 5.0.0
- 4.x-dev
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.2
- 4.1.1
- 4.1.0
- 4.0.1
- 4.0.0
- 3.x-dev
- 3.12.1
- 3.12.0
- 3.11.0
- 3.10.0
- 3.9.0
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.0
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.0
- 2.8.0
- 2.7.0
- 2.6.0
- 2.5.1
- 2.5.0
- 2.4.1
- 2.4.0
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.1
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.x-dev
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-166581-vorschau-sichtbarkeit
- dev-symfony_6
- dev-ordered-list-breadcrumbs
- dev-php8-3.x
- dev-HEAD
- dev-135579_Navigation-Bundle-BEM-verwenden--temp
This package is auto-updated.
Last update: 2024-12-06 14:50:15 UTC
README
Symfony Bundle featuring:
- 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.
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.
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') }}
Breadcrumbs
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
.
Example:
{# 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:
<?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:
<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.
Credits, Copyright and License
This project was started at webfactory GmbH, Bonn.
Copyright 2015 - 2021 webfactory GmbH, Bonn. Code released under the MIT license.