| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Data\Field; |
| 6: | |
| 7: | use Atk4\Core\InitializerTrait; |
| 8: | use Atk4\Data\Field; |
| 9: | use Atk4\Data\Model; |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | class CallbackField extends Field |
| 15: | { |
| 16: | use InitializerTrait { |
| 17: | init as private _init; |
| 18: | } |
| 19: | |
| 20: | public bool $neverPersist = true; |
| 21: | public bool $readOnly = true; |
| 22: | |
| 23: | |
| 24: | public $expr; |
| 25: | |
| 26: | protected function init(): void |
| 27: | { |
| 28: | $this->_init(); |
| 29: | |
| 30: | $this->ui['table']['sortable'] = false; |
| 31: | |
| 32: | $this->onHookToOwnerEntity(Model::HOOK_AFTER_LOAD, function (Model $entity) { |
| 33: | $entity->getDataRef()[$this->shortName] = ($this->expr)($entity); |
| 34: | }); |
| 35: | } |
| 36: | } |
| 37: | |