jeyroik / extas-fields-conditions
Fields conditions for Extas
Installs: 429
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/jeyroik/extas-fields-conditions
Requires
Requires (Dev)
This package is auto-updated.
Last update: 2025-09-29 02:22:04 UTC
README
Описание
Пакет позволяет настроить для полей условия (проверки) для стадий
- перед созданием
- после создания
- перед обновлением
- после обновления
- перед удаленеим
- после удаления
Использование
Для нашей сущности item настроим две проверки перед созданием:
- Проверим, что значение не равно
test. - Проверим, что сущность с текущим значением отсутствует.
extas.json
{
"fields": [
{
"name": "value",
"parameters": {
"subject": {
"name": "subject",
"value": "item"
}
},
"before_create": [
{
"condition": "neq",
"value": "test"
},
{
"condition": "empty",
"value": {
"repository": "itemRepository",
"method": "all",
"query": {"value": "@value"}
}
}
]
}
]
}
/** * @method itemRepo() */ $item = new class ([ 'value' => 'test' ]) extends \extas\components\Item { use \extas\components\THasValue; protected function getSubjectForExtension() : string{ return 'item'; } }; try { $this->itemRepo()->create($item); // Exception "Condition failed" } catch (\Exception $e) { } $item->setValue('unique'); $this->itemRepo()->create($item); // ok $this->itemRepo()->create($item); // Exception "Condition failed"