Methods

entityDisplay()

entityDisplay(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : string

Defines how the field will actually display its contents when rendering entities.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Additional array of options

Returns

string —

HTML representation of this field

entityEdit()

entityEdit(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : string

Renders field in edit mode.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

Returns

string —

HTML containing from elements

entityBeforeSave()

entityBeforeSave(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : boolean

Before each entity is saved.

Returning a non-true value will halt the save operation, as stopping the event as well.

The options array contains the _post key, which holds all the information you need to update you field:

$options['_post']

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

Returns

boolean

entityValidate()

entityValidate(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, \Cake\Validation\Validator $validator) : boolean

After an entity is validated as part of save process.

This is where Field Handlers must validate their information.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

\Cake\Validation\Validator $validator

The validator object

Returns

boolean —

False will halt the save process

instanceInfo()

instanceInfo(\Cake\Event\Event $event) : array

Returns an array of information of this field.

  • type (string): Type of data this field stores, possible values are: datetime, decimal, int, text, varchar.

  • name (string): Human readable name of this field. ex. Selectbox Defaults to class name.

  • description (string): Something about what this field does or allows to do. Defaults to class name.

  • hidden (bool): If set to false users can not use this field via Field UI. Defaults to true, users can use it via Field UI.

  • maxInstances (int): Maximum number instances of this field a table can have. Set to 0 to indicates no limits. Defaults to 0.

  • searchable (bool): Whether this field can be searched using WHERE clauses.

Parameters

\Cake\Event\Event $event

The event that was triggered

Returns

array

instanceSettingsForm()

instanceSettingsForm(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : string

Renders all the form elements to be used on the field settings form.

Field settings will be the same for all shared instances of the same field and should define the way the value will be stored in the database.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

string —

HTML form elements for the settings page

instanceViewModeForm()

instanceViewModeForm(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : string

Renders all the form elements to be used on the field view mode form.

Here is where you should render form elements to hold settings about how Entities should be rendered for a particular View Mode.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

string —

HTML form elements for the settings page

instanceViewModeDefaults()

instanceViewModeDefaults(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : array

Returns an array of defaults values for each input in the view modes form.

You can provide different default values depending on the view mode, you can use $option['viewMode'] to distinct between view modes.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

array

implementedEvents()

implementedEvents() : array

Return a list of implemented events.

Events names must be named as follow:

Field.<FieldHandlerName>.<Entity|Instance>.<eventName>

Example:

Field.TextField.Entity.edit

Where:

  • Field: Prefix, the event subspace.
  • TextField: Name of the class for Text Handler in this example.
  • Entity or Instance: "Entity" for events related to entities (an User, a Content, etc), or "Instance" for field instances events.
  • edit: The name of the event.

You can override this method and provide a customized set of event handlers.

Returns

array

entityFieldAttached()

entityFieldAttached(\Cake\Event\Event $event, \Field\Model\Entity\Field $field) : void

Triggered when custom field is attached to entity under the "_fields" property.

This method is commonly used to alter custom field values before it gets attached to entity. For instance, set default values.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

The field that is being attached to entity, you can alter this before field is attached

entityBeforeFind()

entityBeforeFind(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options, boolean $primary) : mixed

Triggered on entity's "beforeFind" event.

Can be used as preprocessor, as fields can directly alter the entity's properties before it's returned as part of a find query.

Returning false will cause the entity to be removed from the resulting find collection. In the other hand, stopping the given event will halt the entire find operation.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

boolean $primary

Whether this event was triggered as part of a primary find query or not

Returns

mixed

entityAfterSave()

entityAfterSave(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : void

After each entity is saved.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

entityBeforeDelete()

entityBeforeDelete(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : boolean

Before an entity is deleted from database.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

Returns

boolean —

False will halt the delete process

entityAfterDelete()

entityAfterDelete(\Cake\Event\Event $event, \Field\Model\Entity\Field $field, array $options) : void

After an entity is deleted from database.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\Field $field

Field information

array $options

Options given as an array

instanceSettingsDefaults()

instanceSettingsDefaults(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : array

Returns an array of default values for field settings form's inputs.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

array

instanceSettingsValidate()

instanceSettingsValidate(\Cake\Event\Event $event, array $settings, \Cake\Validation\Validator $validator) : void

Triggered before instance's settings are changed.

Here Field Handlers can apply custom validation rules to their settings.

Parameters

\Cake\Event\Event $event

The event that was triggered

array $settings

Settings values to be validated

\Cake\Validation\Validator $validator

The validator object

instanceViewModeValidate()

instanceViewModeValidate(\Cake\Event\Event $event, array $settings, \Cake\Validation\Validator $validator) : void

Triggered before instance's view mode settings are changed.

Here Field Handlers can apply custom validation rules to view mode's settings.

Parameters

\Cake\Event\Event $event

The event that was triggered

array $settings

View mode's setting values to be validated

\Cake\Validation\Validator $validator

The validator object

instanceBeforeAttach()

instanceBeforeAttach(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : boolean

Before an new instance of this field is attached to a database table.

Stopping this event or returning false will abort the attach operation.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

boolean —

False will halt the attach process

instanceAfterAttach()

instanceAfterAttach(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : void

After an new instance of this field is attached to a database table.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

instanceBeforeDetach()

instanceBeforeDetach(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : boolean

Before an instance of this field is detached from a database table.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance information

array $options

Options given as an array

Returns

boolean —

False will halt the detach process

instanceAfterDetach()

instanceAfterDetach(\Cake\Event\Event $event, \Field\Model\Entity\FieldInstance $instance, array $options) : void

After an instance of this field was detached from a database table.

Here is when you should remove all the stored data for this instance from the DB. For example, if your field stores physical files for every entity, then you should delete those files.

NOTE: By default QuickApps CMS, automatically removes all related records from the field_values table.

Parameters

\Cake\Event\Event $event

The event that was triggered

\Field\Model\Entity\FieldInstance $instance

Instance entity being detached (deleted from "field_instances" table)

array $options

Options given as an 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

shortcodes()

shortcodes(string $content, object|null $context) : string

Look for shortcodes in the given text.

If any is found an event is triggered asking for its Event Lister method. For example:

{nice_button color=green}Click Me!{/nice_button}

You must define an Event Lister nice_button:

class YourListener implements EventListenerInterface {
    public function implementedEvents() {
        return ['nice_button' => 'shortcodeNiceButton'];
    }

    public function shortcodeNiceButton(Event $event, $atts, $content, $tag) {
        // return some text
    }
}

As you can see shortcodes methods will receive three arguments:

$atts

Array which may include any arbitrary attributes that are specified by the user. Attribute names are always converted to lowercase before they are passed into the handler function. Values remains untouched.

{some_shortcode Foo="bAr" /}

Produces:

$atts = ['foo' => 'bAr'];

TIP: Don't use camelCase or UPPER-CASE for your $atts attribute names

$content

Holds the enclosed content (if the shortcode is used in its enclosing form). For self-closing shortcodes $content will be null:

{self_close some=thing /}

$tag

The shortcode name. i.e.: some_shortcode

Parameters

string $content

The the text to parse

object|null $context

Context to use when triggering events

Returns

string —

Orginal string modified with no shortcodes [..]

stripShortcodes()

stripShortcodes(string $content) : string

Removes all shortcodes from the given content.

Parameters

string $content

Text from which to remove shortcodes

Returns

string —

Content without shortcodes

escapeShortcodes()

escapeShortcodes(string $content) : string

Escapes all shortcodes from the given content.

Parameters

string $content

Text from which to escape shortcodes

Returns

string —

Content with all shortcodes escaped

enableShortcodes()

enableShortcodes() : void

Enables shortcode parser.

disableShortcodes()

disableShortcodes() : void

Globally disables shortcode parser.

The shortcodes() method will not work when disabled.