<?php
/**
 * Abstract Choice type handler
 *
 * @author Elze Kool <info@visualmedia.nl>
 */

namespace VisualM\FormBundle\Form\TypeHandler;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use VisualM\FormBundle\Entity\FormField;

/**
 * Abstract Choice type handler
 *
 * @author Elze Kool <info@visualmedia.nl>
 */
abstract class AbstractChoiceTypeHandler implements FormTypeHandlerInterface
{
    /**
     * {@inheritdoc}
     */
    public function getSymfonyType(FormField $formField)
    {
        return ChoiceType::class;
    }

    /**
     * Create Choices from Waarden
     *
     * @param string $waarden Waarden
     *
     * @return array<string> Choices
     */
    protected function createChoices($waarden)
    {
        $choices = [];
        foreach (explode("\n", $waarden) as $waarde) {
            $choices[trim($waarde)] = trim($waarde);
        }
        return $choices;
    }
    
}

