diff --git a/meta/i18n/fr/lean.api.json b/meta/i18n/fr/lean.api.json index 54c4c42..0403645 100644 --- a/meta/i18n/fr/lean.api.json +++ b/meta/i18n/fr/lean.api.json @@ -1,4 +1,15 @@ { + "descriptor": { + "form": { + "none": "Aucun formulaire existant pour cet API" + }, + "entity": { + "none": "Aucune entité trouvée pour cet API" + }, + "route": { + "none": "Aucune route trouvée pour cet API" + } + }, "form": { "save": { "error": { diff --git a/src/Attribute/EntityField.php b/src/Attribute/EntityField.php index 1b01327..129a16c 100644 --- a/src/Attribute/EntityField.php +++ b/src/Attribute/EntityField.php @@ -13,5 +13,6 @@ class EntityField public ?string $regexFormat = null, public mixed $example = null, public ?string $field = null, + public ?string $setterMethod = null, ) {} } \ No newline at end of file diff --git a/src/Form/Save.php b/src/Form/Save.php index 9a36ecd..d5c69e3 100644 --- a/src/Form/Save.php +++ b/src/Form/Save.php @@ -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}; } } } diff --git a/view/lean-api/entity_descriptor.phtml b/view/lean-api/entity_descriptor.phtml index 5ccda65..a6b2639 100644 --- a/view/lean-api/entity_descriptor.phtml +++ b/view/lean-api/entity_descriptor.phtml @@ -1,8 +1,10 @@ +{% language.set "lean.api.descriptor.entity" %} + {% function yesOrNo(bool $toggle) : void %} {{ $toggle ? 'oui' : 'non' }} {% endfunction %} -{% function length(int|null $length): void %} +{% function length(int|null|string $length): void %} {{ $length ?? "non-défini" }} {% endfunction %} @@ -61,5 +63,7 @@ {% endforeach %} + {% or %} + {% _ "none" %} {% endforeach %} \ No newline at end of file diff --git a/view/lean-api/form_descriptor.phtml b/view/lean-api/form_descriptor.phtml index 91c6e9f..7681698 100644 --- a/view/lean-api/form_descriptor.phtml +++ b/view/lean-api/form_descriptor.phtml @@ -1,3 +1,5 @@ +{% language.set "lean.api.descriptor.form" %} + {% function yesOrNo(bool $toggle) : void %} {{ $toggle ? 'oui' : 'non' }} {% endfunction %} @@ -34,5 +36,7 @@ {% endforeach %} + {% or %} + {% _ "none" %} {% endforeach %} \ No newline at end of file diff --git a/view/lean-api/route_descriptor.phtml b/view/lean-api/route_descriptor.phtml index e52f582..bc9fb28 100644 --- a/view/lean-api/route_descriptor.phtml +++ b/view/lean-api/route_descriptor.phtml @@ -1,14 +1,21 @@ +{% language.set "lean.api.descriptor.route" %} +