- WIP on route descriptor
This commit is contained in:
1 parent
21f315cc22
commit
ad310ffee5
7 files changed
+52
-18
No files matched your search
@@ -13,5 +13,6 @@ class EntityField
|
||||
public ?string $regexFormat = null,
|
||||
public mixed $example = null,
|
||||
public ?string $field = null,
|
||||
public ?string $setterMethod = null,
|
||||
) {}
|
||||
}
|
||||
+16
-10
@@ -33,10 +33,14 @@ abstract class Save implements \Picea\Ui\Method\FormInterface {
|
||||
$entity = $this->getEntity();
|
||||
|
||||
if ($entity->isLoaded() ) {
|
||||
$entity->updatedAt = new Datetime();
|
||||
if (property_exists($entity, 'updatedAt')) {
|
||||
$entity->updatedAt = new Datetime();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$entity->createdAt = new Datetime();
|
||||
if (property_exists($entity, 'createdAt')) {
|
||||
$entity->createdAt = new Datetime();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -63,18 +67,20 @@ abstract class Save implements \Picea\Ui\Method\FormInterface {
|
||||
foreach($entity::resolveEntity()->fieldList() as $key => $property) {
|
||||
$field = $property->getAttribute(Field::class)->object;
|
||||
|
||||
if (! $field->readonly) {
|
||||
if (! $field->readonly || ! $entity->isLoaded()) {
|
||||
$apiField = $property->getAttribute(EntityField::class)->object ?? null;
|
||||
|
||||
if ($apiField) {
|
||||
if ($apiField->field) {
|
||||
if ( isset($context->{$apiField->field}) ) {
|
||||
$entity->$key = $context->{$apiField->field};
|
||||
$var = $apiField->field ?: $key;
|
||||
|
||||
if ( isset($context->{$var}) ) {
|
||||
if ($apiField->setterMethod) {
|
||||
# Use a setter method
|
||||
call_user_func([ $entity, $apiField->setterMethod ], $context->{$var});
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ( isset($context->{$key}) ) {
|
||||
$entity->$key = $context->{$key};
|
||||
else {
|
||||
# Direct property set
|
||||
$entity->$key = $context->{$var};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user