sonata-project / SonataMediaBundle

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

Editing media with provider file does not work #2426

Closed haivala closed 4 months ago

haivala commented 10 months ago

Environment

Sonata packages

show

``` $ composer show --latest 'sonata-project/*' Direct dependencies required in composer.json: sonata-project/admin-bundle 4.28.1 4.28.1 The missing Symfony Admin Generator sonata-project/classification-bundle 4.7.1 4.7.1 Symfony SonataClassificationBundle sonata-project/doctrine-orm-admin-bundle 4.14.1 4.14.1 Integrate Doctrine ORM into the Sona... sonata-project/entity-audit-bundle 1.15.0 1.15.0 Audit for Doctrine Entities sonata-project/formatter-bundle 5.3.0 5.3.0 Symfony SonataFormatterBundle sonata-project/media-bundle 4.10.5 4.10.5 Symfony SonataMediaBundle sonata-project/page-bundle 4.6.1 4.6.1 This bundle provides a Site and Page... sonata-project/seo-bundle 3.7.0 3.7.0 Symfony SonataSeoBundle Transitive dependencies not required in composer.json: sonata-project/block-bundle 5.0.1 5.0.1 Symfony SonataBlockBundle sonata-project/doctrine-extensions 2.3.0 2.3.0 Doctrine2 behavioral extensions sonata-project/exporter 3.3.0 3.3.0 Lightweight Exporter library sonata-project/form-extensions 2.1.0 2.1.0 Symfony form extensions sonata-project/twig-extensions 2.3.0 2.3.0 Sonata twig extensions ```

Symfony packages

show

``` Direct dependencies required in composer.json: symfony/console v6.3.8 v6.3.8 Eases the creation of beautiful and test... symfony/debug-bundle v6.3.2 v6.3.2 Provides a tight integration of the Symf... symfony/dotenv v6.3.7 v6.3.7 Registers environment variables from a .... symfony/flex v2.4.1 v2.4.1 Composer plugin for Symfony symfony/framework-bundle v6.3.8 v6.3.8 Provides a tight integration between Sym... symfony/http-client v6.3.8 v6.3.8 Provides powerful methods to fetch HTTP ... symfony/mailer v6.3.5 v6.3.5 Helps sending emails symfony/maker-bundle v1.51.1 v1.51.1 Symfony Maker helps you create empty com... symfony/monolog-bridge v6.3.8 v6.3.8 Provides integration for Monolog with va... symfony/monolog-bundle v3.10.0 v3.10.0 Symfony MonologBundle symfony/notifier v6.3.6 v6.3.6 Sends notifications via one or more chan... symfony/stopwatch v6.3.0 v6.3.0 Provides a way to profile code symfony/telegram-notifier v6.3.5 v6.3.5 Symfony Telegram Notifier Bridge symfony/ux-translator v2.13.2 v2.13.2 Exposes Symfony Translations directly to... symfony/ux-turbo v2.13.2 v2.13.2 Hotwire Turbo integration for Symfony symfony/web-link v6.3.0 v6.3.0 Manages links between resources symfony/web-profiler-bundle v6.3.8 v6.3.8 Provides a development tool that gives d... symfony/webpack-encore-bundle v1.17.2 v2.1.1 Integration with your Symfony app & Webp... symfony/yaml v6.3.8 v6.3.8 Loads and dumps YAML files Transitive dependencies not required in composer.json: symfony/asset v6.3.8 v6.3.8 Manages URL generation and versioning of... symfony/cache v6.3.8 v6.3.8 Provides extended PSR-6, PSR-16 (and tag... symfony/cache-contracts v3.4.0 v3.4.0 Generic abstractions related to caching symfony/clock v6.3.4 v6.3.4 Decouples applications from the system c... symfony/config v6.3.8 v6.3.8 Helps you find, load, combine, autofill ... symfony/dependency-injection v6.3.8 v6.3.8 Allows you to standardize and centralize... symfony/deprecation-contracts v3.4.0 v3.4.0 A generic function and convention to tri... symfony/doctrine-bridge v6.3.8 v6.3.8 Provides integration for Doctrine with v... symfony/error-handler v6.3.5 v6.3.5 Provides tools to manage errors and ease... symfony/event-dispatcher v6.3.2 v6.3.2 Provides tools that allow your applicati... symfony/event-dispatcher-contracts v3.4.0 v3.4.0 Generic abstractions related to dispatch... symfony/expression-language v6.3.0 v6.3.0 Provides an engine that can compile and ... symfony/filesystem v6.3.1 v6.3.1 Provides basic utilities for the filesystem symfony/finder v6.3.5 v6.3.5 Finds files and directories via an intui... symfony/form v6.3.8 v6.3.8 Allows to easily create, process and reu... symfony/http-client-contracts v3.4.0 v3.4.0 Generic abstractions related to HTTP cli... symfony/http-foundation v6.3.8 v6.3.8 Defines an object-oriented layer for the... symfony/http-kernel v6.3.8 v6.3.8 Provides a structured process for conver... symfony/intl v6.3.7 v6.3.7 Provides access to the localization data... symfony/mime v6.3.5 v6.3.5 Allows manipulating MIME messages symfony/options-resolver v6.3.0 v6.3.0 Provides an improved replacement for the... symfony/password-hasher v6.3.8 v6.3.8 Provides password hashing utilities symfony/polyfill-ctype v1.28.0 v1.28.0 Symfony polyfill for ctype functions symfony/polyfill-intl-grapheme v1.28.0 v1.28.0 Symfony polyfill for intl's grapheme_* f... symfony/polyfill-intl-icu v1.28.0 v1.28.0 Symfony polyfill for intl's ICU-related ... symfony/polyfill-intl-idn v1.28.0 v1.28.0 Symfony polyfill for intl's idn_to_ascii... symfony/polyfill-intl-normalizer v1.28.0 v1.28.0 Symfony polyfill for intl's Normalizer c... symfony/polyfill-mbstring v1.28.0 v1.28.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php72 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 7.... symfony/polyfill-php80 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 8.... symfony/polyfill-php81 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 8.... symfony/polyfill-php83 v1.28.0 v1.28.0 Symfony polyfill backporting some PHP 8.... symfony/process v6.3.4 v6.3.4 Executes commands in sub-processes symfony/property-access v6.3.2 v6.3.2 Provides functions to read and write fro... symfony/property-info v6.3.0 v6.3.0 Extracts information about PHP class' pr... symfony/psr-http-message-bridge v2.3.1 v2.3.1 PSR HTTP message bridge symfony/routing v6.3.5 v6.3.5 Maps an HTTP request to a set of configu... symfony/security-acl v3.3.2 v3.3.2 Symfony Security Component - ACL (Access... symfony/security-bundle v6.3.8 v6.3.8 Provides a tight integration of the Secu... symfony/security-core v6.3.7 v6.3.7 Symfony Security Component - Core Library symfony/security-csrf v6.3.2 v6.3.2 Symfony Security Component - CSRF Library symfony/security-http v6.3.8 v6.3.8 Symfony Security Component - HTTP Integr... symfony/serializer v6.3.8 v6.3.8 Handles serializing and deserializing da... symfony/service-contracts v3.4.0 v3.4.0 Generic abstractions related to writing ... symfony/stimulus-bundle v2.13.2 v2.13.2 Integration with your Symfony app & Stim... symfony/string v6.3.8 v6.3.8 Provides an object-oriented API to strin... symfony/translation v6.3.7 v6.3.7 Provides tools to internationalize your ... symfony/translation-contracts v3.4.0 v3.4.0 Generic abstractions related to translation symfony/twig-bridge v6.3.8 v6.3.8 Provides integration for Twig with vario... symfony/twig-bundle v6.3.8 v6.3.8 Provides a tight integration of Twig int... symfony/validator v6.3.8 v6.3.8 Provides tools to validate values symfony/var-dumper v6.3.8 v6.3.8 Provides mechanisms for walking through ... symfony/var-exporter v6.3.6 v6.3.6 Allows exporting any serializable PHP da... ```

PHP version

$ php -v
PHP 8.2.12 (cli) (built: Oct 28 2023 02:10:03) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.12, Copyright (c), by Zend Technologies

Subject

When I try to edit media that has type file edit route does not work anymore

Minimal repository with the bug

Steps to reproduce

  1. Have media with file provider
  2. Try to edit it

    Expected results

    You can edit it

    Actual results

    I have context item and it has small format but file provider should not use it. An exception has been thrown during the rendering of a template ("Unsupported format "item_small"."). it comes from in vendor/sonata-project/media-bundle/src/Resources/views/MediaAdmin/edit.html.twig (line 88)

VincentLanglet commented 10 months ago

When I try to edit media that has type file edit route does not work anymore

In which version does it work ?

haivala commented 10 months ago

When I try to edit media that has type file edit route does not work anymore

In which version does it work ?

That is a good question. Haven't had to edit such media for 2 years. I was hoping if someone else would have the same problem to see if its new

haivala commented 5 months ago

https://github.com/sonata-project/SonataMediaBundle/blob/4.x/src/Resources/views/MediaAdmin/edit.html.twig#L88

this is my config:

    post_medias:
      providers:
        - sonata.media.provider.youtube
        - sonata.media.provider.image
        - sonata.media.provider.vimeo
        - sonata.media.provider.file
      formats:
        small: { width: 400, quality: 60 }
        normal: { width: 600, quality: 70 }
        big: { width: 800, quality: 85 }
haivala commented 5 months ago

Is there a way to exclude the file provider to use formats as it only needs the reference format?

u03c1 commented 5 months ago

I just fall into the same issue this evening.

@haivala A workaround can be to use a custom edit.html.twig and add some exit statement if object.provider is file. You can use setTemplates on your service definition with the key "edit", like in this exemple: https://docs.sonata-project.org/projects/SonataMediaBundle/en/3.x/reference/creating_a_provider_class/?highlight=settemplate#register-the-class-with-the-service-container

@VincentLanglet I do not know the project very well, but do you suggest another place to fix this, as a file obviously can't have format like an image ?

haivala commented 5 months ago

@u03c1 The thing is that it has worked before but in that 2 years period something happened. I remember that the page worked and it showed those image sizes on file provider but the links of course were 404

u03c1 commented 5 months ago

Well, my guess is that it was introduced here: https://github.com/sonata-project/SonataMediaBundle/pull/2090/files

And especially with this line https://github.com/sonata-project/SonataMediaBundle/blob/1f8bee3c639c70eb431396716894fce20da640b9/src/Thumbnail/FileThumbnail.php#L31

I can't understand the purpose of this FORMAT_ADMIN statement, as 'format' argument seems to be useless for a file, but this can exists to respect the full implementation and contracts (?). In fact all the 'thumbnails' calls seems to be irrelevant.

As a file can't have "format", I think we should always send back 'reference url' when we call generatePublicUrl(). May be the FileThumbnail can be removed and we can directly address this at the FileProvider level. In all cases for the twig part, i "think" we should remove the loop on format if the provider is "file", so we don't display unnecessary fields.

As I don't know the code base and history, it's only assumptions.

VincentLanglet commented 5 months ago

Does removing the check solves all your problems ? If yes, please open a Pr with this change, it seems ok to merge it

u03c1 commented 5 months ago

It seems to work at first glance, but I have not tested this further. I haven't a clean install of sonataAdmin 4.x installed to run the test suite. IDK if it's quick and easy to setup all and create a PR following the contributing guide. Will check when I have time.