- WIP on Forms

This commit is contained in:
Dave M. 2025-07-17 18:39:57 +00:00
parent 2dbcfbcb2e
commit 0e0f004bc1
3 changed files with 47 additions and 4 deletions

View File

@ -24,7 +24,7 @@ trait FormTrait
}
}
protected function lang(string $key, array $variables = [])
public function lang(string $key, array $variables = [])
{
return $this->languageHandler->languageFromKey($key, $variables);
}

View File

@ -66,10 +66,9 @@ abstract class Save implements \Picea\Ui\Method\FormInterface {
$field = $property->getAttribute(Field::class)->object;
if (! $field->readonly || ! $entity->isLoaded()) {
$apiField = $property->getAttribute(EntityField::class)->object ?? null;
if ($apiField) {
$var = $apiField->field ?: $key;
if ( isset($context->{$var}) ) {
if ($apiField->setterMethod) {
# Use a setter method

View File

@ -2,4 +2,48 @@
namespace Lean\Api\Lib;
class FormContext extends \Picea\Ui\Method\FormContext { }
use Lean\Api\Factory\MessageFactoryInterface;
use Lean\LanguageHandler;
use Psr\Http\Message\ServerRequestInterface;
class FormContext extends \Picea\Ui\Method\FormContext {
public function __construct(
protected LanguageHandler $languageHandler,
protected MessageFactoryInterface $message,
ServerRequestInterface $request,
? string $formName = null
)
{
parent::__construct($request, $formName);
}
public function lang(string $key, array $variables = [])
{
return $this->languageHandler->languageFromKey($key, $variables);
}
public function pushSuccessMessage($key, $variables = []) {
$this->pushMessage($this->message::generateSuccess(
$this->lang($key, $variables)
));
}
public function pushWarningMessage($key, $variables = []) {
$this->pushMessage($this->message::generateWarning(
$this->lang($key, $variables)
));
}
public function pushErrorMessage($key, $variables = []) {
$this->pushMessage($this->message::generateError(
$this->lang($key, $variables)
));
}
public function pushInfoMessage($key, $variables = []) {
$this->pushMessage($this->message::generateInfo(
$this->lang($key, $variables)
));
}
}