Have you seen our new video tutorials? Check it out!

Navigation Module

Powerful navigation management made easy.

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.