sonata-project / SonataFormatterBundle

Symfony SonataFormatterBundle
https://docs.sonata-project.org/projects/SonataFormatterBundle
MIT License
81 stars 117 forks source link

Media context does not work with CKEditor #191

Closed JonathanBaudoin closed 4 years ago

JonathanBaudoin commented 8 years ago

Environment

Sonata packages

$ composer show sonata-project/*
sonata-project/admin-bundle              3.x-dev 4cc8449    The missing Symfony Admin Generator
sonata-project/block-bundle              3.x-dev 565d0a7    Symfony SonataBlockBundle
sonata-project/cache                     1.0.7              Cache library
sonata-project/classification-bundle     dev-master b89d2f8 Symfony SonataClassificationBundle
sonata-project/core-bundle               3.x-dev 8e1cdbd    Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2                Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.x-dev e974094    Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.1.10             Symfony SonataEasyExtendsBundle
sonata-project/exporter                  1.4.1              Lightweight Exporter library
sonata-project/formatter-bundle          3.x-dev 1f4d7f3    Symfony SonataFormatterBundle
sonata-project/google-authenticator      1.0.2              Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle               2.2.4              Symfony SonataIntlBundle
sonata-project/media-bundle              3.x-dev 61027c5    Symfony SonataMediaBundle
sonata-project/notification-bundle       3.0.0              Symfony SonataNotificationBundle
sonata-project/user-bundle               3.x-dev 33fada8    Symfony SonataUserBundle

Symfony packages

$ composer show symfony/*
symfony/assetic-bundle     v2.8.0  Integrates Assetic into Symfony2
symfony/monolog-bundle     2.11.1  Symfony MonologBundle
symfony/polyfill-apcu      v1.2.0  Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.2.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.2.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.2.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55     v1.2.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56     v1.2.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.2.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.2.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.3.11 Symfony SwiftmailerBundle
symfony/symfony            v2.8.7  The Symfony PHP framework

PHP version

$ php -v
PHP 5.6.22-1+donate.sury.org~trusty+1 (cli) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.3.3, Copyright (c) 2002-2015, by Derick Rethans

Subject

Hi,

I use a CKEditor type in a textarea in the configureFormFields(). It works, except the image browser.

When I want to add an image in my textarea, a modal opens, with a button to browse my images. I can see images from default context (which is defined in the ivory_ck_editor config as default context), but not images from an other context. It's because in the URL, the category param is always set to the default context category, even when I choose an other context. I specify that all my images have categories.

I try to edit SonataFormatterBundle/Controller/CkeditorAdminController:browserAction at line 60:

<?php
# SonataFormatterBundle/Controller/CkeditorAdminController

# After:
if ($this->getRequest()->get('category'))

# Now:
if ($this->getRequest()->get('category') && count($datagrid->getResults()) == 0)

And it works, I can see my images when I change context. But I can't use this solution in a long time. I saw this issue, which seems to be the same, but it seems to be unresolved yet.

Tim4c commented 8 years ago

Hi, i have tryied your solution but it doesn't work than expected ! However, i have found this (just above):

$category = null;
if ($this->container->has('sonata.media.manager.category')) {
     $category = $this->container->get('sonata.media.manager.category')->getRootCategory($context);
}

I think the category media manager is not in Sonata Media but in Sonata Classification.

$category = null;
if ($this->container->has('sonata.classification.manager.category')) {
        $category = $this->container->get('sonata.classification.manager.category')->getRootCategory($context);
}

It work's ! Hope this will be usefull !

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.