- WIP on Forms
This commit is contained in:
		
							parent
							
								
									2dbcfbcb2e
								
							
						
					
					
						commit
						0e0f004bc1
					
				@ -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);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
        ));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user