<?php
namespace App\Form\Type\BackOffice;
use App\Entity\Assay\AnalysisMethod;
use Closure;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\NotNull;
class AnalysisMethodSimulationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'analysisMethod',
EntityType::class,
[
'class' => AnalysisMethod::class,
'choices' => $options['analysisMethods'],
'choice_label' => Closure::fromCallable([$this, 'analysisMethodChoiceLabel']),
'constraints' => [new NotNull()],
]
);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'analysisMethods' => null,
]
);
}
/** @noinspection PhpUnusedPrivateMethodInspection */
private function analysisMethodChoiceLabel(?AnalysisMethod $analysisMethod): string
{
if (!$analysisMethod) {
return '';
}
return sprintf(
'[%s] %s (%s)',
$analysisMethod->getRef(),
$analysisMethod->getName(),
$analysisMethod->getVersion()
);
}
/** @noinspection PhpUnusedPrivateMethodInspection */
private function analysisMethodChoiceValue(?AnalysisMethod $analysisMethod): string
{
if (!$analysisMethod) {
return '';
}
return $analysisMethod->getAnalysisMethodId();
}
}