diff --git a/src/AdminPanel/Form/AbstractInput.php b/src/AdminPanel/Form/AbstractInput.php new file mode 100644 index 0000000..7934d92 --- /dev/null +++ b/src/AdminPanel/Form/AbstractInput.php @@ -0,0 +1,30 @@ + $value); + } + + public function getTemplate(): string + { + $arr = explode('\\', get_class($this)); + $tpName = strtolower( + str_replace( + "Input", + "", + $arr[count($arr) - 1] + ) + ); + return "@AdminPanel/form/" . $tpName . ".twig"; + } +} diff --git a/src/AdminPanel/Form/ChoiceInput.php b/src/AdminPanel/Form/ChoiceInput.php index 121a1cb..d96865d 100644 --- a/src/AdminPanel/Form/ChoiceInput.php +++ b/src/AdminPanel/Form/ChoiceInput.php @@ -2,19 +2,12 @@ namespace AdminPanel\Form; -class ChoiceInput extends TextInput +class ChoiceInput extends AbstractInput { public function getOptions(): array { return array( - 'label', - 'value', 'choices' ); } - - public function getTemplate(): string - { - return "@AdminPanel/form/choice.twig"; - } } diff --git a/src/AdminPanel/Form/DateInput.php b/src/AdminPanel/Form/DateInput.php index 06edaed..e468c5f 100644 --- a/src/AdminPanel/Form/DateInput.php +++ b/src/AdminPanel/Form/DateInput.php @@ -2,18 +2,6 @@ namespace AdminPanel\Form; -class DateInput extends TextInput +class DateInput extends AbstractInput { - public function getOptions(): array - { - return array( - 'label', - 'value', - ); - } - - public function getTemplate(): string - { - return "@AdminPanel/form/date.twig"; - } } diff --git a/src/AdminPanel/Form/EntityInput.php b/src/AdminPanel/Form/EntityInput.php index bbbcab2..18c2a7b 100644 --- a/src/AdminPanel/Form/EntityInput.php +++ b/src/AdminPanel/Form/EntityInput.php @@ -4,12 +4,11 @@ namespace AdminPanel\Form; use AdminPanel\AdminPanel; -class EntityInput implements Input +class EntityInput extends AbstractInput { public function getOptions(): array { return array( - 'label', 'entity' ); } @@ -25,9 +24,4 @@ class EntityInput implements Input $optionName => $value ); } - - public function getTemplate(): string - { - return "@AdminPanel/form/entity.twig"; - } } diff --git a/src/AdminPanel/Form/TextInput.php b/src/AdminPanel/Form/TextInput.php index 854458d..350cee8 100644 --- a/src/AdminPanel/Form/TextInput.php +++ b/src/AdminPanel/Form/TextInput.php @@ -18,11 +18,12 @@ class TextInput implements Input public function getTemplate(): string { + $arr = explode('\\', self::class); $tpName = strtolower( str_replace( "Input", "", - str_split('\\', self::class)[1] + $arr[count($arr) - 1] ) ); return "@AdminPanel/form/" . $tpName . ".twig";