sonata-project / SonataMediaBundle

Symfony SonataMediaBundle
https://docs.sonata-project.org/projects/SonataMediaBundle
MIT License
451 stars 495 forks source link

Add image on sonata_type_collection error 500 #1266

Closed lelledaniele closed 4 years ago

lelledaniele commented 7 years ago

Environment

Sonata packages

sonata-project/admin-bundle              3.18.2 The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.2  Symfony SonataBlockBundle
sonata-project/cache                     1.0.7  Cache library
sonata-project/classification-bundle     3.3.0  Symfony SonataClassificationBundle
sonata-project/core-bundle               3.4.0  Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.4  Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.2.0  Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.7.1  Lightweight Exporter library
sonata-project/media-bundle              3.5.1  Symfony SonataMediaBundle
sonata-project/notification-bundle       3.1.0  Symfony SonataNotificationBundle

Symfony packages

symfony/assetic-bundle     v2.8.1  Integrates Assetic into Symfony2
symfony/monolog-bundle     v2.12.1 Symfony MonologBundle
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.3.0  Symfony utilities for portability of PHP codes
symfony/security-acl       v3.0.0  Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.6.2  Symfony SwiftmailerBundle
symfony/symfony            v3.2.8  The Symfony PHP framework

PHP version

PHP 7.1.6-1~ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun  9 2017 08:26:34)

Subject

I am having a 500 error when I try to add another image on sonata_type_collection field. To avoid this issue there are two methods:

Steps to reproduce

  1. Create a new "Itinerary Experience" record with sonata admin
  2. Click on "Add new" in the Images section
  3. Choose a file
  4. Click on "Add new" in the Images section
  5. In the Symfony AJAX request should appear a 500 error

POST parameters request

[
  "title" => ""
  "description" => ""
  "supplier" => ""
  "price" => ""
  "currency" => ""
  "priceType" => "per_person"
  "images" => [
    [
      "position" => "0"
    ]
  ]
  "_token" => "kCFBYSMDyEQ0kPLchleuHHoFskSpud4EZBQlGm6GBas"
]

The 500 error will NOT appear if you skip the 3rd step.

POST parameters request WITHOUT 3rd step

[
  "title" => "hjkghg"
  "description" => "gjkghj"
  "supplier" => ""
  "price" => "777"
  "currency" => "AFA"
  "priceType" => "per_person"
  "images" => [
    [
      "media" => [
        "binaryContent" => ""
      ]
      "position" => "0"
    ]
  ]
  "_token" => "ZIMiAn7jYp2MytTe5Cr0iPtvTxXiRJJSPBsog74pXc8"
]

Expected results

Show the row with the image inputs screenshot from 2017-06-29 10-32-43

Actual results

An exception has been thrown during the rendering of a template ("Parameter "id" for route "admin_sonata_media_media_edit" must match "[^/]++" ("" given) to generate a corresponding URL.") in "SonataMediaBundle:Form:media_widgets.html.twig".

Configuration

Entities

class ItineraryBoxExperience extends ItineraryBox
{
    /**
     * @ORM\OneToMany(targetEntity="\SmithOak\MediaBundle\Entity\ItineraryBoxExperienceImages" , mappedBy="itineraryBoxExperience" , cascade={"all"}, orphanRemoval=true)
     * @ORM\OrderBy({"position" = "ASC"})
     */
    private $images = null;
}
class ItineraryBoxExperienceImages
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @ORM\ManyToOne(targetEntity="\SmithOak\ItineraryBundle\Entity\ItineraryBoxExperience", inversedBy="images")
     * @ORM\JoinColumn(name="itinerary_box_experience", referencedColumnName="id")
     */
    private $itineraryBoxExperience;
}

Form - Images Section

->add('images', 'sonata_type_collection',
                    [
                        'required' => false,
                        'label' => 'Images',
                        'by_reference' => false
                    ],
                    [
                        'edit' => 'inline',
                        'inline' => 'table',
                        'link_parameters' => [
                            'context' => 'content_block'
                        ],
                        'limit' => 3
                    ]
                );

Please let me know if you need more details. Many thanks

greg0ire commented 7 years ago

Please let me know if you need more details.

You mean like a stack trace? That would be great.

lelledaniele commented 7 years ago

Hi @greg0ire,

Here the stack trace.

stack_trace.txt

thanks

stale[bot] commented 4 years ago

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.