Added Input objects

This commit is contained in:
Florian Bouillon 2019-04-17 01:31:00 +02:00
parent 0dfe90ebf6
commit ca0150ca0b
5 changed files with 117 additions and 0 deletions

View File

@ -0,0 +1,15 @@
<?php
namespace AdminPanel\Form;
class ChoiceInput extends TextInput
{
public function getOptions(): array
{
return array(
'label',
'value',
'choices'
);
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace AdminPanel\Form;
class DateInput extends TextInput
{
public function getOptions(): array
{
return array(
'label',
'value',
);
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace AdminPanel\Form;
use AdminPanel\AdminPanel;
class EntityInput implements Input
{
public function getOptions(): array
{
return array(
'label',
'entity'
);
}
public function processOption(string $optionName, $value): array
{
if ($optionName === 'entity') {
return array(
'entities' => AdminPanel::getInstance()->getEm()->getRepository($value)->findAll()
);
}
return array(
$optionName => $value
);
}
public function getTemplate(): string
{
return "@AdminPanel/form/entity.twig";
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace AdminPanel\Form;
interface Input
{
/**
* get definable options in form
* some are processed elsewhere like
* name, value
*
* @return array
*/
public function getOptions(): array;
/**
* run things when you got option
*
* @param string $optionName
* @param mixed $value
*
* @return array
*/
public function processOption(string $optionName, $value): array;
/**
* Get template file
*
* @return string
*/
public function getTemplate(): string;
}

View File

@ -0,0 +1,23 @@
<?php
namespace AdminPanel\Form;
class TextInput implements Input
{
public function getOptions(): array
{
return array(
);
}
public function processOption(string $optionName, $value): array
{
return array($optionName => $value);
}
public function getTemplate(): string
{
return "@AdminPanel/form/text.twig";
}
}