Introduction

anomaly.module.navigation

The navigation module provides an extensible and powerful navigation management system.

Features

The Navigation module comes with everything you need to make powerful navigation menus.

  • Multiple Menus
  • Flexible menu output.
  • Extension-based link types.

Installation

You can install the Navigation module with the addon:install command:

php artisan addon:install anomaly.module.navigation
Notice: The Navigation module comes installed with PyroCMS out of the box.

Usage

This section will show you how to use the addon via API and in the view layer.

Menus

Menus are stream entries that represent a collection of links.

Menu Fields

Below is a list of fields in the menus stream. Fields are accessed as attributes:

$menu->name;

Same goes for decorated instances in Twig:

{{ menu.name }}
Fields
Key Type Description

name

text

The menu name.

slug

slug

The menu API slug.

description

textarea

The menu description.

Menu Interface

This section will go over the \Anomaly\NavigationModule\Menu\Contract\MenuInterface class.

MenuInterface::getLinks()

The getLinks method returns a collection of the related menu links.

Returns: \Anomaly\NavigationModule\Link\LinkCollection
Example
foreach ($menu->getLinks() as $link) {
    echo $link->getUrl();
}
Twig
{% for link in menu.getLinks() %}
    {{ link.getUrl() }}
{% endfor %}
MenuInterface::links()

The links method returns the link relation.

Returns: \Illuminate\Database\Eloquent\Relations\HasMany
Example
foreach ($menu->links()->where('parent_id', 1)->get() as $link) {
    echo $link->getUrl();
}
Twig
{% for link in menu.links().where('parent_id', 1).get() %}
    {{ link.getUrl() }}
{% endfor %}

Menu Repository

This class will go over the \Anomaly\NavigationModule\Menu\Contract\MenuRepositoryInterface

MenuRepositoryInterface::findBySlug()

The findBySlug method returns a menu it's slug.

Returns: \Anomaly\NavigationModule\Menu\Contract\MenuInterface or null
Arguments
Key Required Type Default Description

$slug

true

string

none

The slug of the menu to find.

Links

Links are stream entries that belong to a menu. Links use extensions called link type extensions to define how they work.

Link Fields

Below is a list of fields in the links stream. Fields are accessed as attributes:

$link->title;

Same goes for decorated instances in Twig:

{{ link.title }}
Fields
Key Required Type Default Description

menu

true

relationship

none

The related menu.

type

true

addon

none

The link type extension.

entry

true

polymorphic

none

The related link information per link type.

target

true

select

none

The link's target attribute.

class

false

text

null

The link class.

parent

false

relationship

null

The related parent link.

allowed_roles

false

multiple

null

The user roles allowed to view the link.

Link Interface

This section will go over the \Anomaly\NavigationModule\Link\Contract\LinkInterface class.

LinkInterface::getUrl()

The getUrl method returns the link's URL via it's extension.

Returns: string
Example
$link->getUrl();
Twig
{{ link.getUrl() }}
LinkInterface::getTitle()

The getTitle returns the link title via it's extension.

Returns: string
Example
$link->getTitle();
Twig
{{ link.getTitle() }}

Plugin

This section will go over how to use the plugin that comes with the Navigation module.

menu

The menu function let's you generate navigation structure based on the specified navigation menu.

The returned plugin criteria will render the resulting navigation automatically using __toString() if you do not explicitly call render().

Returns: \Anomaly\Streams\Platform\Addon\Plugin\PluginCriteria
Arguments
Key Required Type Default Description

$root

false

mixed

none

The id, instance, or path of the root navigation link.

Twig
{{ menu()|raw }}

{# Showing child navigation #}
{{ menu('about')
    .linkAttributesDropdown({'data-toggle': 'dropdown'})
    .listClass('nav navbar-nav navbar-right')
    .childListClass('dropdown-menu')
    .render()|raw }}
Available Options

The menu function uses the plugin criteria to allow you to configure options for the resulting navigation.

Options are defined by chaining together camelCase methods:

{{ menu().optionOne('example')|raw }} // Results in option_one = example

So to define dropdown_class for example you would do this:

{{ menu().dropdownClass('dropdown')|raw }}
Pro Tip: Defining criteria options this way is standard throughout Pyro!
Options
Key Required Default Description

view

false

anomaly.module.navigation::links

The base view to render the navigation from.

macro

false

anomaly.module.navigation::macro

The macro to use for rendering the navigation.

depth

false

none

The maximum depth of the navigation.

list_tag

false

ul

The list tag to use.

list_class

false

none

The list class to use.

item_tag

false

li

The list item tag to use.

item_class

false

none

The list item class to use.

dropdown_class

false

dropdown

The CSS class for links containing child links.

active_class

false

active

The CSS class for links that are selected or whose child link is selected.

selected_class

false

current

The CSS class for the currently selected navigation link.

link_class

false

none

The CSS class to use for links.

link_attributes

false

[]

An array of key value html attributes for links.

link_attributes_dropdown

false

[]

An array of key value html attributes for links that have a dropdown.

child_list_tag

false

list_tag

The list tag for child lists.

child_list_class

false

none

The list class for child lists.

dropdown_toggle

false

none

The dropdown toggle tag to use in the case a dropdown toggle is desired.

dropdown_toggle_class

false

none

The dropdown toggle class to use in the case a dropdown toggle is desired.

dropdown_toggle_attributes

false

[]

An array of key value html attributes for the dropdown toggle.

dropdown_toggle_text

false

none

The text or HTML to display inside the dropdown toggle.

links

The links function returns the links in a specified menu.

To return the collection of links use the get() trigger on the plugin criteria (see example below).

Returns: \Anomaly\NavigationModule\Link\LinkCollection
Arguments
Key Required Type Default Description

$menu

true

string

none

The slug of the menu to return links for.

Twig
{% for link in links('footer').get() %}
<p>
    <a href="{{ link.url }}">{{ link.title }}</a>
</p>
{% endfor %}
Available Options

The links function uses the plugin criteria to allow you to configure options for the resulting navigation.

Options are defined by chaining together camelCase methods:

{{ links().optionOne('example')|raw }} // Results in option_one = example

So to define dropdown_class for example you would do this:

{{ links().dropdownClass('dropdown')|raw }}
Pro Tip: Defining criteria options this way is standard throughout Pyro!
Options
Key Required Default Description

root

false

none

The id or path of the root link to start navigation from.