silasjoisten / sonata-multiupload-bundle

MIT License
30 stars 16 forks source link

Argument 1 passed to Sonata\AdminBundle\Controller\CRUDController::get() must be of the type string, null given, called in /var/www/html/Project/vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php on line 55 #61

Closed simbu-g2t closed 5 years ago

simbu-g2t commented 5 years ago

Environment

Sonata packages

$ composer show --latest 'sonata-project/*'
sonata-project/admin-bundle              3.52.0 3.53.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.17.0 3.17.0 Symfony SonataBlockBundle
sonata-project/cache                     1.1.1  2.0.1  Cache library
sonata-project/cache-bundle              2.4.2  3.1.0  This bundle provides caching services
sonata-project/core-bundle               3.17.0 3.17.0 Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.5.0  3.0.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.3.0  1.3.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.10.0 3.10.0 Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.5.0  2.5.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  2.0.1  2.0.1  Lightweight Exporter library
sonata-project/formatter-bundle          4.1.3  4.1.3  Symfony SonataFormatterBundle
sonata-project/media-bundle              3.20.1 3.20.1 Symfony SonataMediaBundle
sonata-project/notification-bundle       3.6.2  3.6.2  Symfony SonataNotificationBundle
sonata-project/page-bundle               3.11.1 3.12.0 This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.7.0  2.7.0  Symfony SonataSeoBundle

PHP version

$ php -v
PHP 7.2.21-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Aug  7 2019 09:53:51) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.21-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Subject

I've installed and added this route(admin_sonata_media_media_multi_upload) to my admin menu. I got the below error while clicking the menu link (http://www.example.com/admin/sonata/media/media/multi-upload)

Argument 1 passed to Sonata\AdminBundle\Controller\CRUDController::get() must be of the type string, null given, called in /var/www/html/Project/vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php on line 55

Steps to reproduce

Follow the 3 steps upto adding parameter in config/services.yaml which is explained in this bundle doc

Expected results

Multiple file upload

Actual results

Argument 1 passed to Sonata\AdminBundle\Controller\CRUDController::get() must be of the type string, null given, called in /var/www/html/Project/vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php on line 55

silasjoisten commented 5 years ago

Hello @simbu-g2t sorry for the delay. What are you trying to upload? And at this line it tries to get the Provider did you registered it?

simbu-g2t commented 5 years ago

How to register the provider? Can you guide me or give the code?

FYI: I'm new to sonata and symfony

It's working if I add the provider(sonata.media.provider.image) at line number 51 in /vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php like $providerName = $request->query->get('provider','sonata.media.provider.image');

silasjoisten commented 5 years ago

@simbu-g2t So what kind of provider are you trying to use?

silasjoisten commented 5 years ago

It's working if I add the provider(sonata.media.provider.image) at line number 51 in /vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php like $providerName = $request->query->get('provider','sonata.media.provider.image');

In your snippet you are setting a default for provider. if there is no query parameter it will use the default. This behaviour is not so graceful. The logic requires a registered provider otherwise the app has no idea how to handle file/image/video etc.

Are you using default "select provider" view from Sonata or are you trying to generate a direkt url to image multi upload?

simbu-g2t commented 5 years ago

Currently I'm using direct URL for multiple upload. It is better if we can able to select provider. I don't know how to do that. This is my sonata_media.yaml

# config/packages/sonata_media.yaml

sonata_media:
    # if you don't use default namespace configuration
    class:
        media: App\Application\Sonata\MediaBundle\Entity\Media
        gallery: App\Application\Sonata\MediaBundle\Entity\Gallery
        gallery_has_media: App\Application\Sonata\MediaBundle\Entity\GalleryHasMedia
    db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
    default_context: default # you need to set a context
    contexts:
        default:  # the default context is mandatory
            providers:
                - sonata.media.provider.dailymotion
                - sonata.media.provider.youtube
                - sonata.media.provider.image
                - sonata.media.provider.file
                - sonata.media.provider.vimeo

            formats:
                admin: { width: 100 , height: 100 , quality: 80}
                small: { width: 200 , quality: 80}
                medium: { width: 3000 , quality: 80}
                big:   { width: 500 , quality: 70}
        blog:  # the default context is mandatory
            providers:
                - sonata.media.provider.image
                - sonata.media.provider.file

            formats:
                admin: { width: 100 , height: 100 , quality: 80}
                small: { width: 200 , quality: 80}
                medium: { width: 3000 , quality: 80}
                big:   { width: 500 , quality: 70}

    cdn:
        server:
            path: /uploads/media # http://media.sonata-project.org/

    filesystem:
        local:
            directory:  '%kernel.root_dir%/../public/uploads/media'
            create:     false
silasjoisten commented 5 years ago

@simbu-g2t Okay so you are generating a direct multi upload link to the multi upload action. You need to pass the provider query parameter.

And for the selection of an provider go to the media grid/list view and it should be done automatically when you click on new

  1. Bildschirmfoto 2019-09-13 um 14 42 34

  2. This is the page to select Provider (to get the route you can use bin/console debug:router command) and create an link to that Bildschirmfoto 2019-09-13 um 14 42 47
  3. Bildschirmfoto 2019-09-13 um 14 42 56

simbu-g2t commented 5 years ago

But I don't see the provider in that page, Anything need to add in config to see that? Screenshot from 2019-09-13 18-29-15

simbu-g2t commented 5 years ago

From the step 3, I followed this only

parameters:
    sonata.media.admin.media.controller: SilasJoisten\Sonata\MultiUploadBundle\Controller\MultiUploadController

Anything need to do after this?

silasjoisten commented 5 years ago

Do you have a custom provider?

silasjoisten commented 5 years ago

Please read the manual carefully again please you need to do some other things too. You need to override the provider and use a trait.

silasjoisten commented 5 years ago

Maybe see that: https://github.com/silasjoisten/sonata-multiupload-bundle/issues/56#issuecomment-478078904 There is an example for an custom Audio Provider and how to register that

simbu-g2t commented 5 years ago

No, I don't have custom provider right now. Currently I resolved with the below code(added provider in query param) in my sonata_admin.yaml. It's working now with direct URL and I removed the provider query from /vendor/silasjoisten/sonata-multiupload-bundle/src/Controller/MultiUploadController.php

# config/packages/sonata_media.yaml

sonata_admin:
    title: 'Sonata Admin'
    title_logo: images/logo.png
    dashboard:
        groups:
          media:
              label:                Media
              label_catalogue:      ~
              icon:            '<i class="fa fa-image"></i>'
              items:
                  - route:        admin_sonata_media_gallery_list
                    label:        Gallery
                  - route:        admin_sonata_media_media_list
                    label:        Media
                  - route:        admin_sonata_media_media_multi_upload
                    label:        Add Multiple Images
                    route_params:        
                      provider: sonata.media.provider.image

It should be better if I select the provider from media, But I don't know to create a custom provider

simbu-g2t commented 5 years ago

Thanks for your help @silasjoisten