2017 © Pedro Peláez
 

library dot-navigation

DotKernel navigation component

image

dotkernel/dot-navigation

DotKernel navigation component

  • Tuesday, May 15, 2018
  • by dotkernel
  • Repository
  • 2 Watchers
  • 1 Stars
  • 648 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 8 Versions
  • 7 % Grown

The README.md

dot-navigation

OSS Lifecycle PHP from Packagist (specify version), (*1)

GitHub issues GitHub forks GitHub stars GitHub license, (*2)

Build Static codecov, (*3)

SymfonyInsight, (*4)

Allows you to easily define and parse menus inside templates, configuration based approach., (*5)

Installation

Run, (*6)

composer require dotkernel/dot-navigation

Merge ConfigProvider to your application's configuration., (*7)

The package uses dot-helpers package, please merge dot-helpers ConfigProvider to your application's configuration also, if it's not merged already!, (*8)

Register NavigationMiddleware in your middleware pipe between the routing and the dispatching middleware., (*9)

Configuration

Locate dot-navigation's distributable config file vendor/dotkernel/dot-navigation/config/autoload/navigation.global.php.dist and duplicate it in your project as config/autoload/navigation.global.php, (*10)

Components

A menu, or navigation container, is a class implementing the \RecursiveIterator interface. It has a hierarchical structure, with nodes called pages(see the Page class) that may have children. It is basically a tree, (*11)

A Page extends the NavigationContainer class. The NavigationContainer is the top most node which represents the entire menu. The children of this node are Page instances that defines each navigation item., (*12)

A page has a reference to its parent, and can have options and attributes. There are no limitation on what is accepted as options or attributes., (*13)

Options can be any piece of information that describes a page. Some predefined options exists, in order for the navigation module to work seamlessly with other dot modules., (*14)

Attributes are key value pairs that defines the menu item. They are usually inserted as html attributes when parsing the menu, but of course, this is implementation specific., (*15)

A NavigationService class, is the service that handles all defined menu container. It can fetch the container from its provider, check if a page is active or not and get the page's generated URI., (*16)

Container providers

Each menu can be created from different sources. The responsibility of creating a menu container from the source falls on a container provider., (*17)

Each provider must implement the interface ProviderInterface and be registered in the ProviderPluginManager., (*18)

We offer just one provider for now, ArrayProvider, that is able to fetch and create a menu container from a php array that is defined in the configuration file., (*19)

Used to render the navigation container in a displayable format. It can render a simple HTML ul list or use a partial template, to render the menu in a template engine., (*20)

The partial method is usually the more flexible one, custom rules can be defined and checked in the template., (*21)

If you are using twig, there is already a twig extension provided in package dot-twigrenderer, that you can use to easily parse the menus inside your templates, (*22)

When using the partial method, the template will receive as parameters the container, the navigation service and any extra parameters set by the developer., (*23)

Navigation containers are referred, when parsed, by their name, as defined in the configuration file., (*24)

Required page options and attributes

The following are options that each page should define in the configuration, (*25)

  • label - the text of the menu item
  • route or uri - defines the route or link the menu item will have
  • permission - can be used optionally, if authorization service is present, in order to omit menu items that are not authorized to visit.

The Versions