/**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         if ('association' === $metadata['type']) {
             if ($metadata['associationType'] & ClassMetadata::TO_MANY) {
                 $formFieldOptions['attr']['multiple'] = true;
             }
             // supported associations are displayed using advanced JavaScript widgets
             $formFieldOptions['attr']['data-widget'] = 'select2';
         }
         if ('collection' === $metadata['fieldType']) {
             if (!isset($formFieldOptions['allow_add'])) {
                 $formFieldOptions['allow_add'] = true;
             }
             if (!isset($formFieldOptions['allow_delete'])) {
                 $formFieldOptions['allow_delete'] = true;
             }
             // The "delete_empty" option exists as of Sf >= 2.5
             if (class_exists('Symfony\\Component\\Form\\FormErrorIterator')) {
                 if (!isset($formFieldOptions['delete_empty'])) {
                     $formFieldOptions['delete_empty'] = true;
                 }
             }
         } elseif ('checkbox' === $metadata['fieldType'] && !isset($formFieldOptions['required'])) {
             $formFieldOptions['required'] = false;
         }
         if (!isset($formFieldOptions['required'])) {
             if (null !== ($guessRequired = $this->guesser->guessRequired($builder->getOption('data_class'), $name))) {
                 $formFieldOptions['required'] = $guessRequired->getValue();
             }
         }
         // Configure "placeholder" option for entity fields
         if ('association' === $metadata['type'] && $metadata['associationType'] & ClassMetadata::TO_ONE && !isset($formFieldOptions[$placeHolderOptionName = $this->getPlaceholderOptionName()]) && false === $formFieldOptions['required']) {
             $formFieldOptions[$placeHolderOptionName] = 'form.label.empty_value';
         }
         $formFieldOptions['attr']['field_type'] = $metadata['fieldType'];
         $formFieldOptions['attr']['field_css_class'] = $metadata['class'];
         $formFieldOptions['attr']['field_help'] = $metadata['help'];
         $formFieldType = $this->useLegacyFormComponent() ? $metadata['fieldType'] : $this->getFormTypeFqcn($metadata['fieldType']);
         $builder->add($name, $formFieldType, $formFieldOptions);
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         // Configure options using the list of registered type configurators:
         foreach ($this->configurators as $configurator) {
             if ($configurator->supports($metadata['fieldType'], $formFieldOptions, $metadata)) {
                 $formFieldOptions = $configurator->configure($name, $formFieldOptions, $metadata, $builder);
             }
         }
         $formFieldType = $this->useLegacyFormComponent() ? $metadata['fieldType'] : $this->getFormTypeFqcn($metadata['fieldType']);
         $builder->add($name, $formFieldType, $formFieldOptions);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         if ('association' === $metadata['type']) {
             $toManyAssociations = array(ClassMetadata::ONE_TO_MANY, ClassMetadata::MANY_TO_MANY);
             if (in_array($metadata['associationType'], $toManyAssociations)) {
                 $formFieldOptions['attr']['multiple'] = true;
             }
             // supported associations are displayed using advanced JavaScript widgets
             $formFieldOptions['attr']['data-widget'] = 'select2';
         }
         if ('collection' === $metadata['fieldType']) {
             if (!isset($formFieldOptions['allow_add'])) {
                 $formFieldOptions['allow_add'] = true;
             }
             if (!isset($formFieldOptions['allow_delete'])) {
                 $formFieldOptions['allow_delete'] = true;
             }
             if (version_compare(Kernel::VERSION, '2.5.0', '>=')) {
                 if (!isset($formFieldOptions['delete_empty'])) {
                     $formFieldOptions['delete_empty'] = true;
                 }
             }
         } elseif ('checkbox' === $metadata['fieldType'] && !isset($formFieldOptions['required'])) {
             $formFieldOptions['required'] = false;
         }
         if (!isset($formFieldOptions['required'])) {
             if (null !== ($guessRequired = $this->guesser->guessRequired($builder->getOption('data_class'), $name))) {
                 $formFieldOptions['required'] = $guessRequired->getValue();
             }
         }
         $formFieldOptions['attr']['field_type'] = $metadata['fieldType'];
         $formFieldOptions['attr']['field_css_class'] = $metadata['class'];
         $formFieldOptions['attr']['field_help'] = $metadata['help'];
         $formFieldType = $this->useLegacyFormComponent() ? $metadata['fieldType'] : $this->getFormTypeFqcn($metadata['fieldType']);
         $builder->add($name, $formFieldType, $formFieldOptions);
     }
 }
Exemplo n.º 4
0
 /**
  * Merges all the information about the fields associated with the given view
  * to return the complete set of normalized field configuration.
  *
  * @param string $view
  * @param array  $entityConfiguration
  *
  * @return array The complete field configuration
  */
 protected function normalizeFieldsConfiguration($view, $entityConfiguration)
 {
     $fieldsConfiguration = $entityConfiguration[$view]['fields'];
     $configuration = parent::normalizeFieldsConfiguration($view, $entityConfiguration);
     //override the sortable
     foreach ($fieldsConfiguration as $fieldName => $fieldConfiguration) {
         if (isset($fieldConfiguration['sortable'])) {
             $configuration[$fieldName]['sortable'] = $fieldConfiguration['sortable'];
         }
     }
     return $configuration;
 }
Exemplo n.º 5
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $entity = $options['entity'];
     $view = $options['view'];
     $entityConfig = $this->configurator->getEntityConfiguration($entity);
     $entityProperties = $entityConfig[$view]['fields'];
     foreach ($entityProperties as $name => $metadata) {
         $formFieldOptions = $metadata['type_options'];
         if ('association' === $metadata['type']) {
             // *-to-many associations are not supported yet
             $toManyAssociations = array(ClassMetadata::ONE_TO_MANY, ClassMetadata::MANY_TO_MANY);
             if (in_array($metadata['associationType'], $toManyAssociations)) {
                 continue;
             }
             // supported associations are displayed using advanced JavaScript widgets
             $formFieldOptions['attr']['data-widget'] = 'select2';
         }
         if ('collection' === $metadata['fieldType']) {
             if (!isset($formFieldOptions['allow_add'])) {
                 $formFieldOptions['allow_add'] = true;
             }
             if (!isset($formFieldOptions['allow_delete'])) {
                 $formFieldOptions['allow_delete'] = true;
             }
             if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '2.5.0', '>=')) {
                 if (!isset($formFieldOptions['delete_empty'])) {
                     $formFieldOptions['delete_empty'] = true;
                 }
             }
         } elseif ('checkbox' === $metadata['fieldType'] && !isset($formFieldOptions['required'])) {
             $formFieldOptions['required'] = false;
         }
         $formFieldOptions['attr']['field_type'] = $metadata['fieldType'];
         $formFieldOptions['attr']['field_css_class'] = $metadata['class'];
         $formFieldOptions['attr']['field_help'] = $metadata['help'];
         $builder->add($name, $metadata['fieldType'], $formFieldOptions);
     }
 }
 /**
  * @expectedException InvalidArgumentException
  * @expectedExceptionMessage Entity "UnmanagedEntity" is not managed by EasyAdmin.
  */
 public function testAccessingAnUnmanagedEntity()
 {
     $backendConfig = array('easy_admin' => array('entities' => array('AppBundle\\Entity\\TestEntity')));
     $configurator = new Configurator($backendConfig);
     $configurator->getEntityConfiguration('UnmanagedEntity');
 }