mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 13:57:10 +02:00
Optimized RequestedEntityFormBuilderService and implemented form classes and logic
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Form;
|
||||
|
||||
use Symfony\Component\Form\AbstractType as AbstractSymfonyType;
|
||||
|
||||
class AbstractType extends AbstractSymfonyType
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
abstract class AbstractType extends AbstractSymfonyType
|
||||
{
|
||||
}
|
||||
|
21
application/symfony/src/Form/Source/PureSourceType.php
Normal file
21
application/symfony/src/Form/Source/PureSourceType.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Source;
|
||||
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class PureSourceType extends SourceType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Form\AbstractType::buildForm()
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add('slug')->add('class');
|
||||
}
|
||||
}
|
13
application/symfony/src/Form/Source/SourceType.php
Normal file
13
application/symfony/src/Form/Source/SourceType.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Source;
|
||||
|
||||
use App\Form\AbstractType;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class SourceType extends AbstractType
|
||||
{
|
||||
const CLASS_PARAMETER_NAME = 'class';
|
||||
}
|
2
application/symfony/src/Form/Type/README.md
Normal file
2
application/symfony/src/Form/Type/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# Type
|
||||
This folder containes general types.
|
63
application/symfony/src/Form/Type/SourceType.php
Normal file
63
application/symfony/src/Form/Type/SourceType.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use App\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use App\Domain\SourceManagement\SourceClassInformationService;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
final class SourceType extends AbstractType implements SourceTypeInterface
|
||||
{
|
||||
const UNUSED_PRAEFIX = 'App\\Entity\\Source';
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
*
|
||||
* @return string Key which can be used in choice selection
|
||||
*/
|
||||
private function getChoiceKey(string $class): string
|
||||
{
|
||||
return str_replace(self::UNUSED_PRAEFIX, '', $class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getChoices(): array
|
||||
{
|
||||
$choices = [];
|
||||
$sourceClassInformationService = new SourceClassInformationService();
|
||||
$allClasses = $sourceClassInformationService->getAllSourceClasses();
|
||||
foreach ($allClasses as $class) {
|
||||
$choices[$this->getChoiceKey($class)] = $class;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Form\AbstractType::configureOptions()
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'choices' => $this->getChoices(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see \Symfony\Component\Form\AbstractType::getParent()
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return ChoiceType::class;
|
||||
}
|
||||
}
|
12
application/symfony/src/Form/Type/SourceTypeInterface.php
Normal file
12
application/symfony/src/Form/Type/SourceTypeInterface.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\FormTypeInterface;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
interface SourceTypeInterface extends FormTypeInterface
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user