\Field\ControllerFieldUIControllerTrait

Field UI Trait.

Other plugins may extends Field plugin by using this trait in their controllers.

With this trait, Field plugin provides an user friendly UI for manage entity's custom fields. It provides a field-manager user interface (UI) by attaching a series of actions over a clean controller.

Usage:

Beside adding use FieldUIControllerTrait; to your controller you MUST also indicate the name of the table being managed using the $_manageTable property, you must set this property to any valid table alias within your system (dot notation is also allowed). For example:

uses Field\Controller\FieldUIControllerTrait;

class MyCleanController extends <Plugin>AppController {
    use FieldUIControllerTrait;
    protected $_manageTable = 'Content.Contents';
}

Optionally you can indicate a bundle within your table to manage by declaring the $_bundle property:

uses Field\Controller\FieldUIControllerTrait;

class MyCleanController extends <Plugin>AppController {
    use FieldUIControllerTrait;
    protected $_manageTable = 'Content.Contents';
    protected $_bundle = 'articles';
}

Requirements

  • This trait should only be used over a clean controller.
  • You must define $_manageTable property in your controller.
  • Your Controller must be a backend-controller (under Controller\Admin namespace).

Summary

Methods
Properties
Constants
beforeFilter()
beforeRender()
index()
configure()
attach()
detach()
viewModeList()
viewModeEdit()
viewModeMove()
move()
No public properties found
No constants found
_getInstances()
_validateSlug()
_getBundle()
_getOrThrow()
_validateViewMode()
$_table
$_tableAlias
N/A
No private methods found
No private properties found
N/A

Properties

$_table

$_table : \Cake\ORM\Table

Instance of the table being managed.

Type

\Cake\ORM\Table

$_tableAlias

$_tableAlias : string

Table alias name.

Type

string

Methods

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.

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.

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'

_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