\QuickApps\ViewViewModeRegistry

ViewModeRegistry is used as a registry for handling view modes, also provides a few utility methods such as add() & remove().

View modes tells contents how they should be rendered.

Plugins are allowed to register their own view modes at any time. But it is recommended to do this at bootstrap so all plugins will be aware of this new view mode soon as possible.

Summary

Methods
Properties
Constants
uses()
add()
remove()
current()
modes()
No public properties found
No constants found
No protected methods found
$_current
$_modes
N/A
No private methods found
No private properties found
N/A

Properties

$_current

$_current : string

Holds the current view mode being used.

Type

string

$_modes

$_modes : array

Holds an array list of all registered view modes.

Type

array

Methods

uses()

uses(string $slug) : void

Marks as "in use" the given view mode.

The given view mode must be registered first using add(). If you try to switch to an unexisting (unregistered) view mode this method will throw and exception.

Parameters

string $slug

View mode machine name to switch to

Throws

\Cake\Network\Exception\InternalErrorException

When switching to an unregistered view mode

add()

add(string|array $slug, string|null $name, string|null $description) : void

Registers a new view mode. Or overwrite if already exists.

You can register more than one view mode at once by passing an array as first argument and ignore the others two:

ViewModeRegistry::add([
    'slug_1' => [
        'name' => 'View Mode 1',
        'description' => 'Lorem ipsum',
    ],
    'slug_2' => [
        'name' => 'View Mode 2',
        'description' => 'Dolor sit amet',
     ],
]);

Or you can register a single view mode by passing its "slug", "name" and "description" as three separated arguments:

ViewModeRegistry::add('slug-1', 'View Mode 1', 'Lorem ipsum');
ViewModeRegistry::add('slug-2', 'View Mode 2', 'Dolor sit amet');

Parameters

string|array $slug

Slug name of your view mode. e.g.: my-view mode, or an array of view modes to register indexed by slug name

string|null $name

Human readable name. e.g.: My View Mode

string|null $description

A brief description about for what is this view mode

remove()

remove(string|null $slug) : void

Unregisters the given view-mode, or all of them if first parameter is null.

Parameters

string|null $slug

View mode's slug

current()

current(boolean $full) : array|string

Gets the in use view-mode information.

You can get either, slug only or full information as an array.

Parameters

boolean $full

Set to true to get full information as an array, or set to false (by default) to get slug name only

Returns

array|string

modes()

modes(boolean|string $mode) : array

Gets the full list of all registered view modes, or for a single view mode if $viewMode is set to a string value.

You can get either a full list of every registered view mode, or a plain list of slugs of every registered view mode. Or you can get all information for a particular view mode by passing its slug as first argument.

Usage:

Get a list of View Modes slugs:

ViewModeRegistry::modes();
// output: ['teaser', 'full', ...]

Get a full list of every View Mode:

ViewModeRegistry::modes(true);
// output: [
//     'teaser' => [
//         'name' => 'Human readable for teaser mode',
//         'description' => 'Brief description for teaser view-mode'
//     ],
//     'full' => [
//         'name' => 'Human readable for full mode',
//         'description' => 'Brief description for full view-mode'
//     ],
//     ...
// ]

Get full information for a particular View Mode:

ViewModeRegistry::modes('teaser');
// output: [
//     'name' => 'Human readable for teaser mode',
//     'description' => 'Brief description for teaser view-mode'
// ]

Parameters

boolean|string $mode

Set to true to get full list. Or false (by default) to get only the slug of all registered view modes. Or set to a string value to get information for that view mode only.

Throws

\Cake\Network\Exception\InternalErrorException

When you try to get information for a particular View Mode that does not exists

Returns

array