Closed franckentien closed 4 years ago
This is a part of my config.yml:
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:
small: { width: 100 , quality: 70}
cg-small: { height: 200 , quality: 70}
big: { width: 500 , quality: 70}
cg-big: { height: 500 , quality: 70}
I ran in to (possibly?) the same issue, It tracked it down to a series of things colliding, but the necessary fix still escapes me.
Long story short: I can "fix" my local setup by adding a width: false
to those formats I don't want to specify a width for (portrait formats). The reason it works is that https://github.com/sonata-project/SonataMediaBundle/blob/a19f79e76f4ec3d156217512d5c9f90c8507ca89/src/Resizer/SimpleResizer.php#L56 checks whether width is set, not whether it is empty, which allows false
to pass.
Now, why did this suddenly break? My best guess is that the cause of the breakages is not going from 3.18.1 to 3.19.1, but an update to symfony. In my case I could track it down to Symfonys autogenerated dependency injection cache. I managed to get the cache from an old version of my site, it had something like this in it (php 5.6, symfony 2.8.42, media-bundle 2.3.4)
$instance->addFormat('default_landscape', array('width' => 960, 'height' => false, 'quality' => 80, 'format' => 'jpg', 'constraint' => true));
$instance->addFormat('default_portrait', array('height' => 540, 'width' => false, 'quality' => 80, 'format' => 'jpg', 'constraint' => true));
While my latest version of the site (php 7.3, symfony 3.4.30, media-bundle 3.20.1) Reads like this
$instance->addFormat('default_landscape', ['width' => 960, 'height' => NULL, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => false, 'resizer_options' => []]);
$instance->addFormat('default_portrait', ['height' => 540, 'width' => NULL, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => false, 'resizer_options' => []]);
Notice the switch from false
to NULL
I have absolutely no idea whether the main problem here is
isset
as opposed to eg. empty
or something else.
One more update - setting the width to false ended up not working in all situations, so a proper fix is probably necessary get this to work.
Ran into the same issue. Cause in my case was that some formats in sonata_media.yml have defined height but not width. It seems that width is mandatory.
In your case: Try changing
formats:
small: { width: 100 , quality: 70}
cg-small: { height: 200 , quality: 70}
big: { width: 500 , quality: 70}
cg-big: { height: 500 , quality: 70}
To
formats:
small: { width: 100 , quality: 70}
cg-small: { width: 200 , quality: 70}
big: { width: 500 , quality: 70}
cg-big: { width: 500 , quality: 70}
I've got the same problem.
Suggested solution is not working: the problem is that the check is wrongly done.
Code is testing for if (!isset($settings['width']))
that is false also when $settings['width'] = null
.
It should be if (!array_key_exists('width', $settings))
Environment
Sonata packages
Symfony packages
PHP version
Subject
I try to add new media picture from media. I try to downgrade sonata-project/media-bundle from 3.19.1 to 3.18.1 and it's work perfectly.
Expected results
Add a new media
Actual results
I got an error and i can import news media: