\Menu\EventMenuHook

Menu rendering dispatcher.

Summary

Methods
Properties
Constants
implementedEvents()
displayBlock()
cache()
dropCache()
No public properties found
No constants found
No protected methods found
$_cache
N/A
No private methods found
No private properties found
N/A

Properties

$_cache

$_cache : array

Used internally.

Type

array

Methods

implementedEvents()

implementedEvents() : void

Returns a list of hooks this Hook Listener is implementing. When the class is registered in an event manager, each individual method will be associated with the respective event.

displayBlock()

displayBlock(\Cake\Event\Event $event, \Block\Model\Entity\Block $block, array $options) : string

Renders menu's associated block.

If the event name Menu.<handler>.display exists the rendering task will be delegated to this listener by triggering a new event, where <handler> is the Menu Entity's handler property ($menu->handler). If no event is defined this method will render the menu using a series of possible view elements as described below.

This method will look for certain view elements when rendering each menu, if one of this elements is not present it'll look the next one, and so on. These view elements should be defined by Themes by placing them in <MyTheme>/Template/Element.

Render menu based on theme's region & view-mode

render_menu_[region-name]_[view-mode].ctp

Renders the given block based on theme's region-name and view-mode, for example:

  • render_menu_left-sidebar_full.ctp: Render for menus in left-sidebar region when view-mode is full.

  • render_menu_left-sidebar_search-result.ctp: Render for menus in left-sidebar region when view-mode is search-result

  • render_menu_footer_search-result.ctp: Render for menus in footer region when view-mode is search-result.

Render menu based on theme's region

render_menu_[region-name].ctp

Similar as before, but based only on theme's region (and any view-mode), for example:

  • render_menu_right-sidebar.ctp: Render for menus in right-sidebar region.

  • render_menu_left-sidebar.ctp: Render for menus in left-sidebar region.

Default

render_block.ctp

This is the default render, if none of the above is found we try to use this last. Themes can overwrite this view element by creating a new one at ExampleTheme/Template/Element/render_block.ctp.


NOTE: Please note the difference between "_" and "-"

Parameters

\Cake\Event\Event $event

The event that was triggered

\Block\Model\Entity\Block $block

The block being rendered

array $options

Array of options

Returns

string

cache()

cache(null|string $key, mixed $value) : mixed

Reads, writes or search internal class's cache.

Usages:

  • When reading if no cache key is found NULL will be returned. e.g. $null = static::cache('invalid-key');
  • When writing, this method return the value that was written. e.g. $value = static::cache('key', 'value');
  • Set both arguments to NULL to read the whole cache content at the moment. e.g. $allCache = static::cache()
  • Set key to null and value to anything to find the first key holding the given value. e.g. $key = static::cache(null, 'search key for this value'), if no key for the given value is found NULL will be returned.

Examples:

Writing cache:

static::cache('user_name', 'John');
// returns 'John'

static::cache('user_last', 'Locke');
// returns 'Locke'

Reading cache:

static::cache('user_name');
// returns: John

static::cache('unexisting_key');
// returns: null

static::cache();
// Reads the entire cache
// returns: ['user_name' => 'John', 'user_last' => 'Locke']

Searching keys:

static::cache(null, 'Locke');
// returns: user_last

static::cache(null, 'Unexisting Value');
// returns: null

Parameters

null|string $key

Cache key to read or write, set both $key and $value to get the whole cache information

mixed $value

Values to write into the given $key, or null indicates reading from cache

Returns

mixed

dropCache()

dropCache(string|null $key) : void

Drops the entire cache or a specific key.

Usage:

static::dropCache('user_cache'); // removes "user_cache" only
static::dropCache(); // removes every key

Parameters

string|null $key

Cache key to clear, if NULL the entire cache will be erased.