\Menu\View\HelperLinkHelper

Link helper.

Utility helper used by MenuHelper. Provides some utility methods for working with menu links, such as isActive() method which check if the given link matches current URL.

Summary

Methods
Properties
Constants
url()
isActive()
sanitize()
localePrefix()
baseUrl()
trigger()
eventDispatcher()
triggered()
No public properties found
No constants found
_crumbs()
_requestMatches()
_localesPattern()
$_defaultConfig
N/A
No private methods found
No private properties found
N/A

Properties

$_defaultConfig

$_defaultConfig : array

Default configuration for this class.

  • breadcrumbGuessing: Whether to mark an item as "active" if its URL is on the breadcrumb stack. Defaults to true

Type

array

Methods

url()

url(string|array $url) : string

Returns a safe URL string for later use with HtmlHelper.

Parameters

string|array $url

URL given as string or an array compatible with Router::url()

Returns

string

isActive()

isActive(\Cake\Datasource\EntityInterface $item) : boolean

Checks if the given menu link should be marked as active.

If $item->activation is a callable function it will be used to determinate if the link should be active or not, returning true from callable indicates link should be active, false indicates it should not be marked as active. Callable receives current request object as first argument and $item as second.

$item->url property MUST exists if "activation" is not a callable, and can be either:

  • A string representing an external or internal URL (all internal links must starts with "/"). e.g. /user/login

  • An array compatible with \Cake\Routing\Router::url(). e.g. ['controller' => 'users', 'action' => 'login']

Both examples are equivalent.

Parameters

\Cake\Datasource\EntityInterface $item

A menu's item

Returns

boolean

sanitize()

sanitize(string $url) : string

Sanitizes the given URL by making sure it's suitable for menu links.

Parameters

string $url

Item's URL to sanitize

Returns

string —

Valid URL, empty string on error

localePrefix()

localePrefix(string $url) : string

Prepends language code to the given URL if the "url_locale_prefix" directive is enabled.

Parameters

string $url

The URL to fix

Returns

string —

Locale prefixed URL

baseUrl()

baseUrl() : string

Calculates site's base URL.

Returns

string —

Site's base URL

trigger()

trigger(array|string $eventName) : \Cake\Event\Event

Triggers the given event name. This method provides a shortcut for:

$this->trigger('EventName', $arg1, $arg2, ..., $argn);

You can provide a subject to use by passing an array as first arguments where the first element is the event name and the second one is the subject, if no subject is given $this will be used by default:

$this->trigger(['GetTime', new MySubject()], $arg_0, $arg_1, ..., $arg_n);

You can also indicate an EventDispatcher instance to use by prefixing the event name with <InstanceName>::, for instance:

$this->trigger('Blog::EventName', $arg1, $arg2, ..., $argn);

This will use the EventDispacher instance named Blog and will trigger the event EventName within that instance.

Parameters

array|string $eventName

The event name to trigger

Returns

\Cake\Event\Event —

The event object that was fired

eventDispatcher()

eventDispatcher(string $name) : \QuickApps\Event\EventDispatcher

Gets an instance of the given Event Dispatcher name.

Usage:

$this->eventDispatcher('myDispatcher')
    ->trigger('MyEventName', $argument)
    ->result;

Parameters

string $name

Name of the dispatcher to get, defaults to 'default'

Returns

\QuickApps\Event\EventDispatcher

triggered()

triggered(string|null $eventName) : integer|array

Retrieves the number of times an event was triggered, or the complete list of events that were triggered.

Parameters

string|null $eventName

The name of the event, if null returns the entire list of event that were fired

Returns

integer|array

_crumbs()

_crumbs() : array

Gets a list of all URLs present in current crumbs stack.

Returns

array —

List of URLs

_requestMatches()

_requestMatches(string $patterns) : boolean

Check if current request path matches any pattern in a set of patterns.

Parameters

string $patterns

String containing a set of patterns separated by \n, \r or \r\n

Returns

boolean —

TRUE if the path matches a pattern, FALSE otherwise

_localesPattern()

_localesPattern() : string

Returns a regular expression that is used to verify if an URL starts or not with a language prefix.

Example:

(en\-us|fr|es|it)

Returns

string