Symfony\Component\Form\Extension\Core\Type\ChoiceType::getDefaultOptions PHP Method

getDefaultOptions() public method

public getDefaultOptions ( array $options )
$options array
    public function getDefaultOptions(array $options)
    {
        $multiple = isset($options['multiple']) && $options['multiple'];
        $expanded = isset($options['expanded']) && $options['expanded'];

        return array(
            'multiple'          => false,
            'expanded'          => false,
            'choice_list'       => null,
            'choices'           => array(),
            'preferred_choices' => array(),
            'empty_data'        => $multiple || $expanded ? array() : '',
            'empty_value'       => $multiple || $expanded || !isset($options['empty_value']) ? null : '',
            'error_bubbling'    => false,
        );
    }

Usage Example

コード例 #1
0
 public function getDefaultOptions(array $options)
 {
     $options = parent::getDefaultOptions($options);
     $roles = array();
     if (count($options['choices']) == 0) {
         // get roles from the Admin classes
         foreach ($this->pool->getAdminServiceIds() as $id) {
             try {
                 $admin = $this->pool->getInstance($id);
             } catch (\Exception $e) {
                 continue;
             }
             $securityHandler = $admin->getSecurityHandler();
             foreach ($securityHandler->buildSecurityInformation($admin) as $role => $acls) {
                 $roles[$role] = $role;
             }
         }
         // get roles from the service container
         foreach ($this->pool->getContainer()->getParameter('security.role_hierarchy.roles') as $name => $rolesHierarchy) {
             $roles[$name] = $name . ': ' . implode(', ', $rolesHierarchy);
             foreach ($rolesHierarchy as $role) {
                 if (!isset($roles[$role])) {
                     $roles[$role] = $role;
                 }
             }
         }
         $options['choices'] = $roles;
     }
     return $options;
 }
All Usage Examples Of Symfony\Component\Form\Extension\Core\Type\ChoiceType::getDefaultOptions