This topic contains 1 reply, has 2 voices, and was last updated by Andrey Yatsenko 4 years, 4 months ago.
- Topic
Sorry for my bad English.
Im new to oro and I want to get multiple files from user in my form and persist them.
I added my filed to my entity like this:1234567891011/**** @var Collection $files** @ORM\OneToMany(targetEntity="Oro\Bundle\AttachmentBundle\Entity\File", mappedBy="owner",* cascade={"all"}, orphanRemoval=true* ))* @ORM\JoinColumn(name="agent_file_id", referencedColumnName="id", onDelete="SET NULL")***/protected $files;I created a collection type like this:
123456789101112131415161718192021222324252627282930313233343536class FileCollectionType extends AbstractType{public function setDefaultOptions(OptionsResolverInterface $resolver){$resolver->setDefaults(array('allow_add' => true,'allow_delete' => true,'type' => 'oro_file','prototype_name' => '__s_name__','required' => false,'show_form_when_empty' => false,'handle_primary' => false,// 'options' => array(// 'data_class' => 'OroCRM\Bundle\ContactBundle\Entity\Contact'// )));}/*** {@inheritdoc}*/public function getParent(){return 'oro_collection';}/*** {@inheritdoc}*/public function getName(){return 'websys_file_collection_type';}}I added my filed to form type like this:
12345678->add('files','websys_file_collection_type',array('label' => 'oro.attachment.file.label','required' => false,))After a clear cache and schema update my i went to my form page and it was great.
Now i could use + button to add more file fileds and i could choose some files.but when i submited the form with some files (i tried it with one or more files) i got this exception:Fatal error: Call to undefined method Oro\Bundle\EntityConfigBundle\Config\Id\EntityConfigId::getFieldType() in /var/www/html/my_proj/vendor/oro/platform/src/Oro/Bundle/AttachmentBundle/Validator/ConfigFileValidator.php on line 64
so I started debuging:
i find out in ConfigFileValidator class in line 63 :1$fieldConfigId = $entityAttachmentConfig->getId();I saw, when I was using a simple file field before the $fieldConfigId variable was of type “Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId” class, but now when this class want to validate each files in my file collection field $fieldConfigId will be a instance of “Oro\Bundle\EntityConfigBundle\Config\Id\EntityConfigId” class which has no “getFieldType” method and this cause the problem.
with more debuging i realized the only diference between these two validation is $fieldName, when i used a simple file field the $fieldName variable in ConfigFileValidator was name of my field in my entity but when i used a file collection filed, my field name was 0 (it used index to set field name of each file field).
so i discovered in this method of “Oro\Bundle\EntityConfigBundle\Provider\ConfigProvider” class :
1234567891011121314public function getConfig($className, $fieldName = null){if ($className) {$className = $this->getClassName($className);}if ($fieldName) {return $this->configManager->getFieldConfig($this->scope, $className, $fieldName);} elseif ($className) {return $this->configManager->getEntityConfig($this->scope, $className);} else {return $this->configManager->createEntityConfig($this->scope);}}when the field name is a valid field name in line 7 of above code it will go to line 8 and a FieldConfigId instance will be returned but when a file in collection is validating and its field name is 0 it fail at line 7 if and because className it valid it will go to line 10 and an instance of EntityConfigId class will be returned.
how can i solve this problem? is there any better way to do this job?
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.