sonata-project / SonataMediaBundle

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

Argument 1 passed to Sonata\MediaBundle\Provider\Pool::validate() must be an instance of Sonata\CoreBundle\Validator\ErrorElement, instance of Sonata\Form\Validator\ErrorElement given, called in vendor/sonata-project/form-extensions/src/Validator/InlineValidator.php on line 58 #1749

Closed mirlo06 closed 4 years ago

mirlo06 commented 4 years ago

I am not using any custom class. im using Application Sonata Media Bundle with Sonata Admin Bundle. When I am uploading image then I got error :

Argument 1 passed to Sonata\MediaBundle\Provider\Pool::validate() must be an instance of Sonata\CoreBundle\Validator\ErrorElement, instance of Sonata\Form\Validator\ErrorElement given, called in vendor/sonata-project/form-extensions/src/Validator/InlineValidator.php on line 58

This is my composer.json with php7.2

{
    "type": "project",
    "license": "proprietary",
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "doctrine/annotations": "^1.10",
        "friendsofsymfony/jsrouting-bundle": "^2.5",
        "friendsofsymfony/rest-bundle": "^2.7",
        "friendsofsymfony/user-bundle": "^2.1",
        "gedmo/doctrine-extensions": "^2.4",
        "hwi/oauth-bundle": "0.6.x-dev",
        "jms/i18n-routing-bundle": "^3.0",
        "jms/serializer-bundle": "^3.5",
        "jms/translation-bundle": "^1.4",
        "knplabs/knp-paginator-bundle": "^5.2",
        "knpuniversity/oauth2-client-bundle": "^2.0",
        "league/oauth2-google": "^3.0",
        "nelmio/api-doc-bundle": "^2.4",
        "php-http/guzzle6-adapter": "^1.1",
        "php-http/httplug-bundle": "^1.17",
        "samj/doctrine-sluggable-bundle": "^2.0",
        "sensio/framework-extra-bundle": "^5.5",
        "sonata-project/admin-bundle": "^3.56",
        "sonata-project/block-bundle": "^3.19",
        "sonata-project/cache-bundle": "3.2.1",
        "sonata-project/datagrid-bundle": "^2.3",
        "sonata-project/doctrine-orm-admin-bundle": "^3.14",
        "sonata-project/formatter-bundle": "^4.1",
        "sonata-project/google-authenticator": "^2.2",
        "sonata-project/media-bundle": "^3.24",
        "sonata-project/seo-bundle": "^2.10",
        "sonata-project/timeline-bundle": "^3.5",
        "sonata-project/user-bundle": "^4.5",
        "stof/doctrine-extensions-bundle": "^1.3",
        "symfony-cmf/routing-bundle": "^2.3",
        "symfony/acl-bundle": "^2.0",
        "symfony/apache-pack": "^1.0",
        "symfony/console": "4.4.*",
        "symfony/dependency-injection": "4.4.*",
        "symfony/dotenv": "4.4.*",
        "symfony/flex": "^1.3.1",
        "symfony/framework-bundle": "4.4.*",
        "symfony/monolog-bundle": "^3.5",
        "symfony/orm-pack": "^1.0",
        "symfony/swiftmailer-bundle": "^3.4",
        "symfony/twig-bundle": "4.4.*",
        "symfony/twig-pack": "^1.0",
        "symfony/validator": "4.4.*",
        "symfony/webpack-encore-bundle": "^1.7",
        "symfony/yaml": "4.4.*",
        "twig/intl-extra": "^3.0",
        "twig/twig": "^2.10"
    },
    "require-dev": {
        "symfony/maker-bundle": "^1.14",
        "symfony/profiler-pack": "^1.0"
    },
    "config": {
        "disable-tls": true,
        "secure-http": false,
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.4.*"
        }
    }
}
core23 commented 4 years ago

Can you have a look at this @wbloszyk

wbloszyk commented 4 years ago

@mirlo06 Can you run composer show --latest 'sonata-project/*' and copy it here? You do not use bug template. Some information from there are important.

BTW are you register CoreBundle?

mirlo06 commented 4 years ago

@wbloszyk yes its registered as 'Sonata\CoreBundle\SonataCoreBundle' Result of composer show :

sonata-project/admin-bundle              3.68.0 3.68.0 The missing Symfony Admin Generator
sonata-project/block-bundle              3.19.0 3.19.0 Symfony SonataBlockBundle
sonata-project/cache                     2.0.1  2.0.1  Cache library
sonata-project/cache-bundle              3.2.1  3.2.1  This bundle provides caching services
sonata-project/core-bundle               3.20.0 3.20.0 Symfony SonataCoreBundle (abandoned)
sonata-project/datagrid-bundle           2.5.0  3.2.0  Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.6.0  1.6.0  Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.18.0 3.18.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.2.0  2.2.0  Lightweight Exporter library
sonata-project/form-extensions           0.1.1  1.4.0  Symfony form extensions
sonata-project/formatter-bundle          4.1.3  4.1.3  Symfony SonataFormatterBundle
sonata-project/google-authenticator      2.2.0  2.2.0  Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle               2.7.0  2.7.0  Symfony SonataIntlBundle
sonata-project/media-bundle              3.24.0 3.24.0 Symfony SonataMediaBundle
sonata-project/seo-bundle                2.10.0 2.10.0 Symfony SonataSeoBundle
sonata-project/timeline-bundle           3.5.0  3.5.0  Integrates SpyTimelineBundle into Sonata
sonata-project/twig-extensions           0.1.1  1.3.0  Sonata twig extensions
sonata-project/user-bundle               4.5.3  4.5.3  Symfony SonataUserBundle
wbloszyk commented 4 years ago

I will reproduce it and check. I need 2-3 hours for this.

mirlo06 commented 4 years ago

For information i could create media from command using MediaManager service :

        $i_file = "path";
        $media = new \App\Application\Sonata\MediaBundle\Entity\Media();
        $media->setName("image");
        $media->setEnabled(true);
        $media->setContext('default');
        $media->setProviderStatus(1);
        $media->setProviderName('sonata.media.provider.image');
        $media_sizes = getimagesize($i_file);
        $media->setWidth($media_sizes[0]);
        $media->setHeight($media_sizes[1]);
        $media->setBinaryContent($i_file);
        $this->mediaManager->save($media);
wbloszyk commented 4 years ago

It is look like alias in CoreBundle is missing.

https://3v4l.org/DamPl

wbloszyk commented 4 years ago

@core23 @sonata-project/contributors I move class_alias from CoreBundle to form-extensions and all work correct. I add die(); in CoreBundle files and it is not work. Files form CoreBundle are not loaded. Any idea why?

core23 commented 4 years ago

I did not use class_aliases quite often. Maybe @greg0ire could help?

wbloszyk commented 4 years ago

I mean CoreBundle are not load.

jordisala1991 commented 4 years ago

What do you mean? The 100% of the classes are not loaded or just a few? Because I have tried and some parts are loaded, example the SonataCoreBundle class and its dependencies. (not tested the whole bundle)

wbloszyk commented 4 years ago

It mean that alias do not work becouse file is not loaded (not used). When I add:

class_exists(\Sonata\CoreBundle\Validator\ErrorElement::class);

In Sonata\Form\Validator\ErrorElement then all works correct.

jordisala1991 commented 4 years ago

What about adding class exists for all classes on the SonataCoreBundle.php?

wbloszyk commented 4 years ago

This will run @trigger_error too. This mean if we use alias (Sonata\CoreBundle) we must create object by alias (or make class_exist). After make CoreBundle optional (change API to orginal name) we will be able to use object by alias or orginal namespace.

When user will be use alias then got trigger_error.

For now this will fix this issue: https://github.com/sonata-project/form-extensions/pull/100

VincentLanglet commented 4 years ago

form-extension 0.1.2 is released.

@mirlo06 can you confirm the problem is fixed ?

wbloszyk commented 4 years ago

I reproduce this issue. Now is working.

mirlo06 commented 4 years ago

composer update and issue fixed. Thanks a lot.

wbloszyk commented 4 years ago

@mirlo06 Thanks for report this issue. I glad i could help.