Skip to content

Entity: set field value

Plugin ID: eca_set_field_value

Available since: 1.0.0

Allows to set, unset or change the value(s) of any field in an entity.

How to empty an entity reference field

Leaving the Field value empty and using the "Set and clear previous value" method does not work for entity reference fields. Instead, use the Remove value instead of adding it method and provide the current value of the field (e.g. the entity ID) as the Field value. If the removed value is the only value in the field, the field will be empty afterwards.

For an example of this, see this issue.

Fields

Field name — config key: field_name

The machine name of the field, that should be changed. Example: body.value
This field supports tokens.

Type: textfield · Required: no · Default: empty string

Field value — config key: field_value

The new field value.
This field supports tokens.

Type: textarea · Required: no · Default: empty string

Method — config key: method

The method to set an entity, like cleaning the old one, etc..
When using the "Defined by token" option, make sure there is a token with this name: eca_set_field_value_method

Type: select · Required: no · Default: set:clear

Allowed values: set:clear, set:force_clear, set:empty, append:not_full, append:drop_first, append:drop_last, prepend:not_full, prepend:drop_first, prepend:drop_last, remove, clear, _eca_token, ''

Available options:

  • Set and clear previous value: Sets the field to the given value. If the field contained any value before, that will be lost, even if this is a multi-value field.
  • Set only when empty: Sets the field to the given value, but only if the field has been empty before. Otherwise, the previous value will be kept and nothing will be set.
  • Append when not full yet: If the field allows multiple values, the given value will be appended as a new item, if the max. cardinality is not reached yet. Otherwise, this action will be skipped.
  • Append and drop first when full: Same as above, but if the max cardinality has been reached, the first value will be removed and the new value appended to the list.
  • Append and drop last when full: Same as above, but instead of dropping the first, this will drop the last item before appending the new value to the list.
  • Prepend when not full yet: If the field allows multiple values, the given value will be inserted as the first item, if the max. cardinality is not reached yet. Otherwise, this action will be skipped.
  • Prepend and drop first when full: Same as above, but if the max cardinality has been reached, the first value will be removed and the new value inserted at the beginning to the list.
  • Prepend and drop last when full: Same as above, but instead of dropping the first, this will drop the last item before inserting the new value at the beginning of the list.
  • Remove value instead of adding it: Remove the value from a field, if it's contained in the list of existing items. If this removes the last remaining value of the field, then the field will be empty (for an example of this, see this issue).
Strip tags — config key: strip_tags

Remove the tags or not.

Type: checkbox · Required: no · Default: false

Trim — config key: trim

Trims the field value or not.

Type: checkbox · Required: no · Default: false

Save entity — config key: save_entity

Saves the entity or not after setting the value.

Type: checkbox · Required: no · Default: false

Entity — config key: object

Provide the token name of the entity that this action should operate with. Please provide the token name only, without brackets.

Type: textfield · Required: no · Default: empty string

See also: Tokens being forwarded