Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning: array_key_exists() with Avocode #139

Open
rpostolov opened this issue Aug 5, 2014 · 5 comments
Open

Warning: array_key_exists() with Avocode #139

rpostolov opened this issue Aug 5, 2014 · 5 comments

Comments

@rpostolov
Copy link

Hi everyone !

I'm using avocode and vich_uploader with admingenerator to make collection_upload.

I have the form for collection upload , but i have this error when i want to save my uploaded files :

ContextErrorException: Warning: array_key_exists(): The first argument should be either a string or an integer in C:\wamp\www\Tranoi-Symfony\vendor\avocode\form-extensions-bundle\Avocode\FormExtensionsBundle\Form\EventListener\CollectionUploadSubscriber.php line 130

Do someone have an idea ?

Thanks and good day :)

@ioleo
Copy link
Member

ioleo commented Aug 5, 2014

@sescandell Could you take a look? I've not used Async upload yet.

@rpostolov
Copy link
Author

I had a little look to this file :
C:\wamp\www\Tranoi-Symfony\vendor\avocode\form-extensions-bundle\Avocode\FormExtensionsBundle\Form\EventListener\CollectionUploadSubscriber.php

In this file i have this bloc (that correspond with the option 'nameable' int he config for collection_upload:

 if ($this->nameable || $this->editable) {
                // Handle additional uploaded data on AsyncUpload
                foreach ($this->uploads as $uploadKey) {
                    if (array_key_exists($uploadKey, $data)) {
                        $this->additionalContentUploads[$uploadKey] = $data[$uploadKey];
                        unset($data[$uploadKey]);
                    }
                }
            }

Here is th configuration:

        addFormOptions:
            primary_key:          id
            nameable:             false
            editable:             [ legende ]

And looking here :
https://github.com/loostro/FormExtensions/blob/master/Form/EventListener/CollectionUploadSubscriber.php

the bloc is missing.

@rpostolov
Copy link
Author

Someone can help please ?

@rflorent
Copy link

same problem.
It's because $data is empty.
$data only contains uploads key and is unset after setting var uploads.

$this->uploads = $data['uploads'];
unset($data['uploads']);
...
array_key_exists($uploadKey, $data)

Editable : additionnal fields are not rendered

@sescandell
Copy link
Member

Hi there,

Sorry for the long silence,

@rpostolov : could you please show me your code?
I'm using this component and it's working pretty well. Maybe you're in a different context than mine and we don't really handle it in the right way.

Here is some of my code:

// From the FormType
$builder->add('medias', 'afe_collection_upload', array(
                    'primary_key' => 'pathHashed',
                    'label' => false,
                    'sortable' => false,
                    'nameable' => false,
                    'editable' => $options['with_description'] ? array('description') : array(),
                    'allow_add' => true,
                    'allow_delete' => true,
                    'type' => 'my_custom_form_media',
                    'uploadRouteName' => 'async_upload',
                    'autoUpload' => $options['auto_upload'], // true in my configuration
                    'options' => array(
                        'data_class' => Media::class,
                        'media_type' => Media::PICTURE,
                        'for_library' => true,
                        'with_description' => $options['with_description']
                    )
                ));

Avocode form extension configuration:

avocode_form_extensions:
    twig:
        use_form_resources: false
    upload_manager: vich_uploader
    collection_upload:
        async_listener_enabled: true
        async_route_name: async_upload

Actually... nothing very special... maybe main point is I have a "entity in the middle" between my collection and my medias. My model is the following:

Product has one Library
Library has many medias
My sample code form below is part of the LibraryType used inside my ProductType

Maybe with some of your code, we can identify what's not working in your situation,

By the way, did you also check sample here: https://github.com/sescandell/CollectionUploadSample

there is a long time it didn't have been updated, but it should still be working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants