Properties

$theme

$theme : string

In use theme name.

Type

string

$layout

$layout : string

Name of the layout that should be used by current theme.

Type

string

$viewClass

$viewClass : string

The name of the View class controllers sends output to.

Type

string

$components

$components : array

An array containing the names of components controllers uses.

Type

array

$_manageTable

$_manageTable : string

Name of the table managed by Field UI API.

Type

string

$_bundle

$_bundle : string

Name of the bundle within the table being managed.

Type

string

$_table

$_table : \Cake\ORM\Table

Instance of the table being managed.

Type

\Cake\ORM\Table

$_tableAlias

$_tableAlias : string

Table alias name.

Type

string

Methods

__construct()

__construct(\Cake\Network\Request $request, \Cake\Network\Response $response)

Constructor.

Parameters

\Cake\Network\Request $request

Request object for this controller. Can be null for testing, but expect that features that use the request parameters will not work.

\Cake\Network\Response $response

Response object for this controller.

beforeRender()

beforeRender(\Cake\Event\Event $event) : void

Fallback for template location when extending Field UI API.

If controller tries to render an unexisting template under its Template directory, then we try to find that view under Field/Template/FieldUI directory.

Example:

Suppose you are using this trait to manage fields attached to Persons entities. You would probably have a Person plugin and a clean controller as follow:

// http://example.com/admin/person/fields_manager
Person\Controller\FieldsManagerController::index()

The above controller action will try to render /plugins/Person/Template/FieldsManager/index.ctp. But if does not exists then <QuickAppsCorePath>/plugins/Field/Template/FieldUI/index.ctp will be used instead.

Of course you may create your own template and skip this fallback functionality.

Parameters

\Cake\Event\Event $event

the event instance.

beforeFilter()

beforeFilter(\Cake\Event\Event $event) : void

Validation rules.

Parameters

\Cake\Event\Event $event

The event instance.

Throws

\Cake\Network\Exception\ForbiddenException

When

  • $_manageTable is not defined.
  • trait is used in non-controller classes.
  • the controller is not a backend controller.

index()

index() : void

Field UI main action.

Shows all the fields attached to the Table being managed.

configure()

configure(integer $id) : void

Handles a single field instance configuration parameters.

In FormHelper, all fields prefixed with _ will be considered as columns values of the instance being edited. Any other input element will be considered as part of the settings column.

For example: _label, _required and description maps to label, required and description. And some_input, another_input maps to settings.some_input, settings.another_input

Parameters

integer $id

The field instance ID to manage

Throws

\Cake\ORM\Exception\RecordNotFoundException

When no field instance was found

attach()

attach() : void

Attach action.

Attaches a new Field to the table being managed.

detach()

detach(integer $id) : void

Detach action.

Detaches a Field from table being managed.

Parameters

integer $id

ID of the instance to detach

viewModeList()

viewModeList(string $viewMode) : void

View modes.

Shows the list of fields for corresponding view mode.

Parameters

string $viewMode

View mode slug. e.g. rss or default

Throws

\Cake\Network\Exception\NotFoundException

When given view mode does not exists

viewModeEdit()

viewModeEdit(string $viewMode, integer $id) : void

Handles field instance rendering settings for a particular view mode.

Parameters

string $viewMode

View mode slug

integer $id

The field instance ID to manage

Throws

\Cake\ORM\Exception\RecordNotFoundException

When no field instance was found

\Cake\Network\Exception\NotFoundException

When given view mode does not exists

viewModeMove()

viewModeMove(string $viewMode, integer $id, string $direction) : void

Moves a field up or down within a view mode.

The ordering indicates the position they are displayed when entities are rendered in a specific view mode.

Parameters

string $viewMode

View mode slug

integer $id

Field instance id

string $direction

Direction, 'up' or 'down'

Throws

\Cake\ORM\Exception\RecordNotFoundException

When no field instance was found

\Cake\Network\Exception\NotFoundException

When given view mode does not exists

move()

move(integer $id, string $direction) : void

Moves a field up or down.

The ordering indicates the position they are displayed on entity's editing form.

Parameters

integer $id

Field instance id

string $direction

Direction, 'up' or 'down'

isAction()

isAction(string $action) : boolean

Method to check that an action is accessible from a URL.

Override this method to change which controller methods can be reached. The default implementation disallows access to all methods defined on Cake\Controller\Controller or QuickApps\Controller\Controller, and allows all public methods on all subclasses of this class.

Parameters

string $action

The action to check.

Returns

boolean —

Whether or not the method is accessible from a URL.

title()

title(string $titleForLayout) : void

Shortcut for Controller::set('title_for_layout', .

..)

Parameters

string $titleForLayout

The title to use on layout's title tag

description()

description(string $descriptionForLayout) : void

Shortcut for Controller::set('description_for_layout', .

..)

Parameters

string $descriptionForLayout

The description to use as meta-description on layout's head tag

prepareTheme()

prepareTheme() : void

Sets the theme to use.

checkMaintenanceMode()

checkMaintenanceMode() : void

Checks if maintenance is enabled, and renders the corresponding maintenance message.

Login & logout sections of the site still working even on maintenance mode, administrators can access the whole site as well.

Throws

\QuickApps\Controller\QuickApps\Error\SiteUnderMaintenanceException

When site is under maintenance mode

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

viewMode()

viewMode(string|null $slug) : void

Sets a view mode or get current view mode.

Parameters

string|null $slug

Slug name of the view mode

addViewMode()

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

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

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

viewModes()

viewModes(boolean|string $viewMode) : array

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

Parameters

boolean|string $viewMode

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.

Returns

array

onViewMode()

onViewMode(string|array $viewMode, callable $method) : mixed

Runs the given callable when the in-use view mode matches.

You can provide multiple view modes, in that case callable method will be executed if current view mode matches any in the given array.

Usage

// run this only on `teaser` view mode
echo $this->onViewMode('teaser', function () use ($someVar) {
    return $this->element('teaser_element', compact('someVar'));
});

// run this on "teaser" view mode, or "search-result" view mode
echo $this->onViewMode(['teaser', 'search-result'], function () use ($someVar) {
    return $this->element('teaser_or_search_result', compact('someVar'));
});

Parameters

string|array $viewMode

View Mode slug, or an array of slugs

callable $method

A callable function to run, it receives $this as only argument

Returns

mixed —

Callable return

asViewMode()

asViewMode(string|array $viewMode, callable $method) : mixed

Runs the given callable as it were under the given view mode.

Usage

$this->viewMode('full');
echo 'before: ' . $this->viewMode();

echo $this->asViewMode('teaser', function () {
     echo 'callable: ' . $this->viewMode();
});

echo 'after: ' . $this->viewMode();

// output:
// before: full
// callable: teaser
// after: full

Parameters

string|array $viewMode

View Mode slug, or an array of slugs

callable $method

A callable function to run, it receives $this as only argument

Returns

mixed —

Callable return

_getInstances()

_getInstances() : \Cake\Datasource\ResultSetInterface

Returns all field instances attached to the table being managed.

Returns

\Cake\Datasource\ResultSetInterface

_validateSlug()

_validateSlug(\Field\Model\Entity\FieldInstance $instance) : void

Checks that the given instance's slug do not collide with table's real column names.

If collision occurs, an error message will be registered on the given entity.

Parameters

\Field\Model\Entity\FieldInstance $instance

Instance to validate

_getBundle()

_getBundle() : string|null

Gets bundle name.

Returns

string|null

_getOrThrow()

_getOrThrow(integer $id, array $conditions) : \Field\Model\Entity\FieldInstance

Gets the given field instance by ID or throw if not exists.

Parameters

integer $id

Field instance ID

array $conditions

Additional conditions for the WHERE query

Throws

\Cake\ORM\Exception\RecordNotFoundException

When instance was not found

Returns

\Field\Model\Entity\FieldInstance

The instance

_validateViewMode()

_validateViewMode(string $viewMode) : void

Throws if the given view modes does not exists.

Parameters

string $viewMode

The view mode to validate

Throws

\Cake\Network\Exception\NotFoundException

When given view mode does not exists