\Field\Model\EntityField

Mock Field.

This entity represents a table cell and holds the following attributes:

  • name: Machine name of this field. ex. user-age. (Schema equivalent: column name)
  • label: Human readable name of this field e.g.: User Last name.
  • value: Value for this [FieldInstance, Entity] tuple. (Schema equivalent: cell value).
  • extra: Extra information.
  • metadata: A mock entity which holds the following properties describing a column
    • value_id: ID of the value stored in field_values table (from where value comes from).
    • instance_id: ID of the field instance (field_instances table) attached to Table.
    • table_alias: Name of the table this field is attached to. e.g: users.
    • entity_id: ID of the entity to which this field is attached to.
    • handler: Name of the Listener Class a.k.a. Field Handler. ex: Field\Text
    • type: Type of data stored by this field (datetime, decilmal, etc).
    • required: True if required, false otherwise
    • description: Something about this field: e.g.: Please enter your name.
    • settings: Array of additional information handled by this particular field. ex: max_len, min_len, etc
    • view_modes: View modes settings, describes how field should be rendered.
    • entity: Entity object this field is attached to.
    • errors: Validation error messages

Summary

Methods
Properties
Constants
__toString()
__debugInfo()
trigger()
eventDispatcher()
triggered()
viewMode()
addViewMode()
viewModes()
onViewMode()
asViewMode()
$name
$label
$value
$extra
$metadata
No constants found
_getViewModeSettings()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$name

$name : string

Type

string

$label

$label : string

Type

string

$value

$value : string

Type

string

$extra

$extra : string

Type

string

$metadata

$metadata : \Cake\Datasource\EntityInterface

Type

\Cake\Datasource\EntityInterface

Methods

__toString()

__toString() : string

String representation of this field.

Defaults to field's value property.

Returns

string

__debugInfo()

__debugInfo() : array

Returns an array that can be used to describe the internal state of this object.

Returns

array

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

_getViewModeSettings()

_getViewModeSettings() : array

Gets field's View Mode's settings for the in-use View Mode.

Returns

array