Backoffice/Form/Type/Component/SiteChoiceType.php
<?php
namespace OpenOrchestra\Backoffice\Form\Type\Component;
use OpenOrchestra\ModelInterface\Model\SiteInterface;
use OpenOrchestra\ModelInterface\Repository\SiteRepositoryInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* Class SiteChoiceType
*/
class SiteChoiceType extends AbstractType
{
protected $siteRepository;
/**
* @param SiteRepositoryInterface $siteRepository
*/
public function __construct(SiteRepositoryInterface $siteRepository)
{
$this->siteRepository = $siteRepository;
}
/**
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'choices' => $this->getChoices(),
'choices_as_values' => true,
)
);
}
/**
* @return array
*/
protected function getChoices()
{
$sites = $this->siteRepository->findByDeleted(false);
$choices = array();
/** @var SiteInterface $site */
foreach ($sites as $site) {
$choices[$site->getName()] = $site->getSiteId();
}
return $choices;
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'oo_site_choice';
}
/**
* @return string
*/
public function getParent()
{
return 'choice';
}
}