Entity Exists

Last updated on
20 November 2022

This condition is 100% inspired by the core entity_exists process plugin. It uses all the same syntax.

Available configuration keys:

  • entity_type: The machine name of the entity type.

  • negate: (optional) Whether to negate the 'entity_exists' condition. Defaults to FALSE. You can also negate the 'entity_exists' plugin by using 'not:entity_exists' as the plugin id.

  • source: (optional) Property or array of properties on which to evaluate the condition. If not set, the condition will be evaluated on the source passed to the ::evaluate() method, typically the source of the process plugin that is using this condition.

The entity_type can be specified using parens notation.

Examples

1. Re-create the core entity_exists process plugin

The core entity_exists plugin returns the source value if the source value corresponds to an entity that exists. Otherwise it returns NULL. By no setting do_get, the source value "passes through" if the condition is met. By not configuring else_get, we return null if the condition is not met.

process:
  field_tag:
    plugin: if_condition
    source: source_tid
    condition:
      plugin: entity_exists
      entity_type: taxonomy_term

Or equivalently using parens syntax to pass the entity_type:

process:
  field_tag:
    plugin: if_condition
    source: source_tid
    condition: entity_exists(taxonomy_term)

2. Remove tag ids that do not correspond to tags

Assuming source_tag_ids contains taxonomy term ids, we can save ourselves some validation errors by removing values that do not correspond to a valid entity.

process:
  field_tags:
    plugin: filter_on_condition
    source: source_tag_ids
    condition:
      plugin: entity_exists
      entity_type: taxonomy_term

Help improve this page

Page status: No known problems

You can: