Action Condition Types define the logic that determines whether an Action is allowed to execute under specific conditions. This mechanism ensures that actions are only triggered when predefined rules are met.
Each Action has a Conditions Type
field that determines how the execution rules are defined. The system supports two built-in condition types and also allows for custom ones.
When the Basic
type is selected, a simple rule builder UI is displayed, allowing users to define conditions using common logical comparisons. These conditions are evaluated based on the current entity context.
Examples:
When the Script
type is selected, users can write condition logic using the Twig templating language. This provides more flexibility and allows referencing complex expressions and conditions.
Example:
{% set proceed = entity.status == 'completed' and entity.priority > 2 %}
{{ proceed }}
For advanced use cases where neither Basic
nor Script
types are sufficient or performant — for example, when complex data relationships or multiple database lookups are required — the system provides support for Custom Condition Types.
canExecute()
method efficient and avoid unnecessary database queries.To create a new custom condition type, run the following command on the server:
php console.php create action condition type OwnCondition
Here, OwnCondition
is the name of your custom condition class.
This command generates a PHP file with the following structure:
<?php
namespace CustomActionConditionTypes;
use Atro\ActionConditionTypes\AbstractActionConditionType;
use Espo\ORM\Entity;
class OwnCondition extends AbstractActionConditionType
{
public static function getTypeLabel(): string
{
return 'OwnCondition';
}
public static function getEntityName(): string
{
return 'Product';
}
public function canExecute(Entity $action, \stdClass $input): bool
{
return true;
}
}
Method Signature | Description |
---|---|
getTypeLabel() |
Returns the label shown in the UI when selecting this condition type. |
getEntityName() |
Defines which entity type this condition is applicable for. The system uses this to link the condition to the correct context. |
canExecute(Entity $action, \stdClass $input) |
Contains the main logic that determines whether the action is allowed to execute. |