- Big WIP on forms component
This commit is contained in:
1 parent
c0b0681fee
commit
3d50cfaccb
14 files changed
+114
-20
No files matched your search
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Form;
|
||||
|
||||
use Lean\Api\Factory\MessageFactoryInterface;
|
||||
use Lean\LanguageHandler;
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
use Ulmus\EntityCollection;
|
||||
|
||||
abstract class Form
|
||||
{
|
||||
public function __construct(
|
||||
protected LanguageHandler $languageHandler,
|
||||
protected MessageFactoryInterface $message,
|
||||
# public EntityInterface $entity,
|
||||
) {}
|
||||
|
||||
public function initialize(FormContextInterface $context) : void
|
||||
{
|
||||
if(isset($this->contextClass) && ! $context instanceof $this->contextClass ) {
|
||||
throw new \LogicException(
|
||||
sprintf("Your context type should be a %s", $this->contextClass)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function lang(string $key, array $variables = [])
|
||||
{
|
||||
return $this->languageHandler->languageFromKey($key, $variables);
|
||||
}
|
||||
|
||||
public function getEntity() : EntityInterface|EntityCollection
|
||||
{
|
||||
if (! isset($this->entity)) {
|
||||
throw new \InvalidArgumentException($this->lang("lean.api.form.error.entity"));
|
||||
}
|
||||
|
||||
return $this->entity;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user