Optimized RequestedEntityFormBuilderService and implemented form classes and logic

This commit is contained in:
Kevin Frantz
2019-02-03 15:21:45 +01:00
parent c3b8e1a92d
commit ed3062a203
18 changed files with 247 additions and 79 deletions

View File

@@ -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
{
}

View 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');
}
}

View 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';
}

View File

@@ -0,0 +1,2 @@
# Type
This folder containes general types.

View 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;
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Form\Type;
use Symfony\Component\Form\FormTypeInterface;
/**
* @author kevinfrantz
*/
interface SourceTypeInterface extends FormTypeInterface
{
}