diff --git a/composer.json b/composer.json index 0d1d9f6e95..305e67c676 100644 --- a/composer.json +++ b/composer.json @@ -95,7 +95,10 @@ "autoload": { "psr-4": { "Atk4\\Ui\\": "src/" - } + }, + "files": [ + "demos/EntityFieldPair.php" + ] }, "autoload-dev": { "psr-4": { diff --git a/demos/EntityFieldPair.php b/demos/EntityFieldPair.php new file mode 100644 index 0000000000..d7553e2a09 --- /dev/null +++ b/demos/EntityFieldPair.php @@ -0,0 +1,87 @@ +assertIsEntity(); + + $this->entity = $entity; + $this->fieldName = $fieldName; + } + + /** + * @return ModelWithPrefixedFields + */ + public function getModel(): Model + { + return $this->entity->getModel(); + } + + /** + * @return ModelWithPrefixedFields + */ + public function getEntity(): Model + { + return $this->entity; + } + + public function getFieldName(): string + { + return $this->fieldName; + } + + /** + * @phpstan-return TField + */ + public function getField(): Field + { + $field = $this->getModel()->getField($this->getFieldName()); + + return $field; + } + + /** + * @return WrappedId|null + */ + public function get() + { + return $this->getEntity()->get($this->getFieldName()); + } + + /** + * @param WrappedId $value + */ + public function set($value): void + { + $this->getEntity()->set($this->getFieldName(), $value); + } + + public function setNull(): void + { + $this->getEntity()->setNull($this->getFieldName()); + } +}