Sonataadminbundle: Error on MediaAdmin

Created on 17 Jan 2019  路  9Comments  路  Source: sonata-project/SonataAdminBundle

Environment

Linux

Sonata packages

sonata-project/admin-bundle 3.45.1 3.45.1 The missing Symfony Admin Generator
sonata-project/block-bundle 3.14.0 3.14.0 Symfony SonataBlockBundle
sonata-project/cache 1.1.1 2.0.1 Cache library
sonata-project/cache-bundle 2.4.2 3.0.1 This bundle provides caching services
sonata-project/classification-bundle 3.7.1 3.7.1 Symfony SonataClassificationBundle
sonata-project/core-bundle 3.14.1 3.14.1 Symfony SonataCoreBundle
sonata-project/datagrid-bundle 2.4.0 2.4.0 Symfony SonataDatagridBundle
sonata-project/doctrine-extensions 1.1.3 1.1.4 Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.7.0 3.7.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 1.11.0 2.0.0 Lightweight Exporter library
sonata-project/formatter-bundle 3.5.0 4.1.2 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.5.0 2.5.0 Symfony SonataIntlBundle
sonata-project/media-bundle 3.17.1 3.17.1 Symfony SonataMediaBundle
sonata-project/notification-bundle 3.5.1 3.5.1 Symfony SonataNotificationBundle
sonata-project/page-bundle 3.9.1 3.9.1 This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle 2.6.2 2.6.2 Symfony SonataSeoBundle
sonata-project/user-bundle 4.2.3 4.2.3 Symfony SonataUserBundle

Symfony packages

symfony/contracts v1.0.2 v1.0.2 A set of abstractions extracted out of the Symfony components
symfony/monolog-bundle v3.3.1 v3.3.1 Symfony MonologBundle
symfony/phpunit-bridge v3.4.21 v4.2.2 Symfony PHPUnit Bridge
symfony/polyfill-apcu v1.10.0 v1.10.0 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-ctype v1.10.0 v1.10.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-icu v1.10.0 v1.10.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.10.0 v1.10.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-php72 v1.10.0 v1.10.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-util v1.10.0 v1.10.0 Symfony utilities for portability of PHP codes
symfony/security-acl v3.0.1 v3.0.1 Symfony Security Component - ACL (Access Control List)
symfony/swiftmailer-bundle v2.6.7 v3.2.5 Symfony SwiftmailerBundle
symfony/symfony v3.4.21 v4.2.2 The Symfony PHP framework
symfony/webpack-encore-bundle v1.1.0 v1.1.0 Integration with your Symfony app & Webpack Encore!

PHP version

PHP 7.2.12 (cli) (built: Nov 16 2018 04:05:32) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.12, Copyright (c) 1999-2018, by Zend Technologies
with blackfire v1.24.2~linux-musl-x64-non_zts72, https://blackfire.io, by Blackfire

Subject

Neither the property "isImageAvailable" nor one of the methods "isImageAvailable()", "getisImageAvailable()"/"isisImageAvailable()"/"hasisImageAvailable()" or "__call()" exist and have public access in class "Sonata\CoreBundle\Model\Metadata".

on media admin that has media to display.
Seems related to changes on object Metadata (related to CoreBundle, MediaBundle & AdminBundle so i post an issue here)

I think BaseMediaAdmin should use Sonata\AdminBundle\Object\Metadata instead of CoreBundle or BlockBundle one but i'm not sure.

It seems the bug as been introduced by https://github.com/sonata-project/SonataAdminBundle/commit/ea4121520161f30106c0530d7efab7b17b95880b#diff-e4879cf5df9dd1f8cdf9b97f1a8fe2a7R33

I would be glad to provide a PR but i'm not sure that my proposal is the good one

bug unconfirmed

Most helpful comment

@lukepass the fix is contain into SonataAdmin here https://github.com/sonata-project/SonataAdminBundle/commit/b2d74088b610f487f79f353933edd3cdc7a8c222. Just have to wait for the next release i guess ;)

All 9 comments

Hello, I still have this problem in the media page after upgrading to 3.18.1:

Neither the property "isImageAvailable" nor one of the methods "isImageAvailable()", "getisImageAvailable()"/"isisImageAvailable()"/"hasisImageAvailable()" or "__call()" exist and have public access in class "Sonata\BlockBundle\Meta\Metadata".

@bmaziere Confirmed. I also have this issue in 3.18.1.

This is now Sonata\BlockBundle\Meta\Metadata cc @jo66

@lukepass the fix is contain into SonataAdmin here https://github.com/sonata-project/SonataAdminBundle/commit/b2d74088b610f487f79f353933edd3cdc7a8c222. Just have to wait for the next release i guess ;)

Right, next release of admin bundle should fix this bug.

But if you override getObjectMetadata in your admin to set mosaic image, the best is to use Sonata\AdminBundle\Object\Metadata instead of the ones from core and block bundle, so simply replace the use statement.

Right, next release of admin bundle should fix this bug.

But if you override getObjectMetadata in your admin to set mosaic image, the best is to use Sonata\AdminBundle\Object\Metadata instead of the ones from core and block bundle, so simply replace the use statement.

Hello, where should I replace it? I left the media page as it is in stock. Thanks!

Sorry for the double account :)
I solved it by overriding the class, is it correct?

<?php

namespace AppBundle\Admin;

use Sonata\AdminBundle\Object\Metadata;
use Sonata\MediaBundle\Admin\ORM\MediaAdmin as BaseMediaAdmin;
use Sonata\MediaBundle\Provider\MediaProviderInterface;

class MediaAdmin extends BaseMediaAdmin
{
    /**
     * {@inheritdoc}
     */
    public function getObjectMetadata($object)
    {
        $provider = $this->pool->getProvider($object->getProviderName());

        $url = $provider->generatePublicUrl(
            $object,
            $provider->getFormatName($object, MediaProviderInterface::FORMAT_ADMIN)
        );

        return new Metadata($object->getName(), $object->getDescription(), $url);
    }
}
parameters:
    sonata.media.admin.media.class: AppBundle\Admin\MediaAdmin

@lukepass Yes it's seems perfect, the only difference with original file should be the use statement for the Metadata class.

Was this page helpful?
0 / 5 - 0 ratings