sonata-project / SonataFormatterBundle

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

Sonata composer cannot update a rich text block #248

Closed pixel-paul closed 7 years ago

pixel-paul commented 7 years ago

Environment

Sonata packages

sonata-project/admin-bundle              3.16.0             The missing Symfony Admin Generator
sonata-project/block-bundle              3.3.2              Symfony SonataBlockBundle
sonata-project/cache                     1.0.7              Cache library
sonata-project/cache-bundle              2.3.1              This bundle provides caching services
sonata-project/classification-bundle     3.3.0              Symfony SonataClassificationBundle
sonata-project/comment-bundle            3.0.0              Integrate the FOSCommentBundle in the Sonata Project
sonata-project/core-bundle               3.3.0              Symfony SonataCoreBundle
sonata-project/datagrid-bundle           2.2.1              Symfony SonataDatagridBundle
sonata-project/doctrine-extensions       1.0.2              Doctrine2 behavioral extensions
sonata-project/doctrine-orm-admin-bundle 3.1.4              Symfony Sonata / Integrate Doctrine ORM into the SonataAdminBundle
sonata-project/easy-extends-bundle       2.1.10             Symfony SonataEasyExtendsBundle
sonata-project/ecommerce                 dev-master 923b791 E-Commerce solution provided by Sonata
sonata-project/exporter                  1.7.1              Lightweight Exporter library
sonata-project/formatter-bundle          3.2.1              Symfony SonataFormatterBundle
sonata-project/google-authenticator      1.0.2              Library to integrate Google Authenticator into a PHP project
sonata-project/intl-bundle               2.3.0              Symfony SonataIntlBundle
sonata-project/media-bundle              3.5.1              Symfony SonataMediaBundle
sonata-project/news-bundle               3.1.2              Symfony SonataNewsBundle
sonata-project/notification-bundle       3.1.0              Symfony SonataNotificationBundle
sonata-project/page-bundle               3.4.1              This bundle provides a Site and Page management through container and block services
sonata-project/seo-bundle                2.1.0              Symfony SonataSeoBundle
sonata-project/sonata-composer           dev-master 6ebe1f3 
sonata-project/timeline-bundle           3.1.0              Integrates SpyTimelineBundle into Sonata
sonata-project/user-bundle               3.2.3              Symfony SonataUserBundle

Symfony packages

symfony/assetic-bundle     v2.8.1  Integrates Assetic into Symfony2
symfony/monolog-bundle     v3.1.0  Symfony MonologBundle
symfony/phpunit-bridge     v2.8.19 Symfony PHPUnit Bridge
symfony/polyfill-apcu      v1.3.0  Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu  v1.3.0  Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring  v1.3.0  Symfony polyfill for the Mbstring extension
symfony/polyfill-php54     v1.3.0  Symfony polyfill backporting some PHP 5.4+ features to lower PHP versions
symfony/polyfill-php55     v1.3.0  Symfony polyfill backporting some PHP 5.5+ features to lower PHP versions
symfony/polyfill-php56     v1.3.0  Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70     v1.3.0  Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util      v1.3.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.5.4  Symfony SwiftmailerBundle
symfony/symfony            v2.8.18 The Symfony PHP framework

PHP version

PHP 7.0.17 (cli) (built: Mar 16 2017 08:19:49) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.17, Copyright (c) 1999-2017, by Zend Technologies
    with Xdebug v2.5.1, Copyright (c) 2002-2017, by Derick Rethans

Subject

Sonata composer will not update a rich text block

Steps to reproduce

Edit a page Select composer Select a block Add 'Rich Text' Click 'Create'

Expected results

Content is created successfully

Actual results

An error is generated from the ajax update: Template "<b>Insert your custom content here</b>" is not defined. 500 Internal Server Error - Twig_Error_Loader

Stack trace

`Twig_Error_Loader: Template "Insert your custom content here" is not defined. at n/a in /var/www/html/sonata3/vendor/twig/twig/lib/Twig/Loader/Array.php line 80

at Twig_Loader_Array->getCacheKey('<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/vendor/sonata-project/formatter-bundle/Twig/Loader/LoaderSelector.php line 74

at Sonata\FormatterBundle\Twig\Loader\LoaderSelector->getCacheKey('<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/app/cache/dev/classes.php line 3248

at Twig_Environment->getTemplateClass('<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/app/cache/dev/classes.php line 3276

at Twig_Environment->loadTemplate('<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/app/cache/dev/classes.php line 3258

at Twig_Environment->render('<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/vendor/sonata-project/formatter-bundle/Formatter/Pool.php line 140

at Sonata\FormatterBundle\Formatter\Pool->transform('richhtml', '<b>Insert your custom content here</b>')
    in /var/www/html/sonata3/vendor/sonata-project/formatter-bundle/Form/EventListener/FormatterListener.php line 68

at Sonata\FormatterBundle\Form\EventListener\FormatterListener->postSubmit(object(FormEvent), 'form.bind', object(EventDispatcher))
    in  line 

at call_user_func(array(object(FormatterListener), 'postSubmit'), object(FormEvent), 'form.bind', object(EventDispatcher))
    in /var/www/html/sonata3/app/cache/dev/classes.php line 1863

at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(array(array(object(FormatterListener), 'postSubmit')), 'form.bind', object(FormEvent))
    in /var/www/html/sonata3/app/cache/dev/classes.php line 1778

at Symfony\Component\EventDispatcher\EventDispatcher->dispatch('form.bind', object(FormEvent))
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ImmutableEventDispatcher.php line 43

at Symfony\Component\EventDispatcher\ImmutableEventDispatcher->dispatch('form.bind', object(FormEvent))
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 633

at Symfony\Component\Form\Form->submit(array(), true)
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 567

at Symfony\Component\Form\Form->submit(array('settings' => array('content' => array('format' => 'richhtml', 'rawContent' => '<b>Insert your custom content here</b>'))), true)
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/HttpFoundation/HttpFoundationRequestHandler.php line 113

at Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler->handleRequest(object(Form), object(Request))
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/Form/Form.php line 489

at Symfony\Component\Form\Form->handleRequest(object(Request))
    in /var/www/html/sonata3/vendor/sonata-project/admin-bundle/Controller/CRUDController.php line 501

at Sonata\AdminBundle\Controller\CRUDController->createAction()
    in /var/www/html/sonata3/vendor/sonata-project/page-bundle/Controller/BlockAdminController.php line 98

at Sonata\PageBundle\Controller\BlockAdminController->createAction(object(Request))
    in  line 

at call_user_func_array(array(object(BlockAdminController), 'createAction'), array(object(Request)))
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 144

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php line 64

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php line 69

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
    in /var/www/html/sonata3/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php line 185

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in /var/www/html/sonata3/web/app_dev.php line 28`

Referencing #239

greg0ire commented 7 years ago

From https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Loader/String.php#L12

The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use Twig_Loader_Array instead or Twig_Environment::createTemplate().

I picked the first solution, but the second might be the right one, see https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Environment.php#L400

The comment line https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Environment.php#L391 is not very reassuring though...

This one is not very reassuring either https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Loader/String.php#L17

Neither is this one : https://github.com/twigphp/Twig/blob/2.x/lib/Twig/Loader/Array.php#L15

But the least reassuring comment is this one : https://github.com/twigphp/Twig/blob/1.x/lib/Twig/Loader/String.php#L17

greg0ire commented 7 years ago

From @sstok : https://twig.sensiolabs.org/doc/2.x/functions/template_from_string.html https://symfony-devs.slack.com/archives/C3FUK4U22/p1491984607472393, which confirms that the way to go would probably be to use createTemplate, see https://github.com/twigphp/Twig/blob/5527658f0863d18d3cb7035ce250dbdcf830ad88/lib/Twig/Extension/StringLoader.php#L36

Chrysweel commented 7 years ago

I have the same error, I reuse this issue.

I have the same result with field...

    protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('content', 'sonata_formatter_type', array(
                'event_dispatcher' => $formMapper->getFormBuilder()->getEventDispatcher(),
                'format_field'   => 'contentFormatter',
                'format_field_options' => array(
                    'choices' => array('text', 'markdown'),
                    'data' => 'markdown',
                ),
                'source_field'   => 'rawContent',
                'source_field_options'      => array(
                    'attr' => array('class' => 'span10', 'rows' => 20)
                ),
                'listener'       => true,
                'target_field'   => 'content'
            ))

I update my project symfony3.2 ... and now it doesnt work. I am doing some wrong ? I need update some code of formatter ? Are there any solution temporaly ?

And when I create a entity I get the result:

Template "

asdasdasd

" is not defined. 500 Internal Server Error - Twig_Error_Loader

My composer.json is

        "php"                                       : ">=7",
        "symfony/symfony"                           : "v3.2.6",
        "doctrine/orm"                              : "~2.4,>=2.4.5",
        "doctrine/doctrine-bundle"                  : "~1.3@dev",
        "twig/extensions"                           : "1.0.*",
        "symfony/assetic-bundle"                    : "^2.8",
        "symfony/swiftmailer-bundle"                : "^2.5",
        "symfony/monolog-bundle"                    : "v3.1.*",
        "sensio/distribution-bundle"                : "^5.0",
        "sensio/framework-extra-bundle"             : "^3.0.2",
        "incenteev/composer-parameter-handler"      : "~2.0",

        "sonata-project/admin-bundle"               : "3.16.0",
        "sonata-project/doctrine-orm-admin-bundle"  : "3.1.4",
        "sonata-project/doctrine-extensions"        : "1.0.2",
        "sonata-project/exporter"                   : "1.7.1",
        "sonata-project/core-bundle"                : "3.3.0",
        "sonata-project/cache"                      : "1.0.7",
        "sonata-project/datagrid-bundle"            : "2.2.1",
        "sonata-project/google-authenticator"       : "1.0.2",
        "sonata-project/easy-extends-bundle"        : "2.1.10",
        "sonata-project/block-bundle"               : "3.3.2",
        "sonata-project/user-bundle"                : "dev-add_support_for_fos_user2",
        "sonata-project/formatter-bundle"           : "3.2.1",

        "shtumi/useful-bundle"                      : "dev-master",
        "knplabs/knp-menu"                          : "^2.1",
        "stof/doctrine-extensions-bundle"           : "^1.2",
        "ocramius/proxy-manager"                    : "~1.0",
        "doctrine/doctrine-migrations-bundle"       : "^1.0",
        "vich/uploader-bundle"                      : "^1.3",
        "knplabs/knp-gaufrette-bundle"              : "^0.3.0",
        "liip/imagine-bundle"                       : "^1.6",
        "aws/aws-sdk-php"                           : "^3.19",
        "snc/redis-bundle"                          : "2.x-dev",
        "predis/predis"                             : "^1.0",
        "sabre/xml"                                 : "^1.5",
        "jms/serializer-bundle"                     : "1.2.1"
    },
    "require-dev" : {
        "sensio/generator-bundle"                    : "3.1.4",
        "symfony/phpunit-bridge"                     : "v3.2.6",
        "symfony/var-dumper"                         : "^3.2",
        "behat/behat"                                : "^3.1",
        "behat/symfony2-extension"                   : "^2.1",
        "behat/mink"                                 : "^1.7",
        "phpunit/phpunit"                            : "^5.5",
        "behat/mink-extension"                       : "^2.2",
        "behat/mink-browserkit-driver"               : "^1.3",
        "behat/mink-selenium2-driver"                : "1.3.1"
    },

I have in my composer.lock twig version:

"version": "1.x-dev",

Thanks in advance !

greg0ire commented 7 years ago

I am doing some wrong ? I need update some code of formatter ?

No, no

Are there any solution temporaly ?

Blacklist this version of SonataFormatterBundle in Composer

"version": "1.x-dev",

You shouldn't rely on development versions

idhard commented 7 years ago

i had similar issue , downgrade my packaged to "version": "3.2.0" of sonata formatter bundle solve my issue for symfony 2.8

wallforfry commented 7 years ago

I'm in 3.2.0 version with symfony 2.8 and I had similar issue.. Any solution ?

Neodork commented 7 years ago

@wallforfry As mentioned by @idhard you can revert to version 3.2.0. If that doesn't do you can use the patch I shared which reverts the BC commit. You can find it in PR https://github.com/sonata-project/SonataFormatterBundle/pull/239#issuecomment-293290193.

But we should look into the fixes suggested by gregoire to make sure our beloved bundle gets fixed too.

ersah123 commented 7 years ago

Reverting version to 3.2.0 fixes problem on symfony 2.8. But in my case, it arises another error on edit:

Attempted to call an undefined method named "validateBlock" of class "Sonata\FormatterBundle\Block\FormatterBlockService".

I applied patch which @Neodork mentions, and now it works without any problem: https://github.com/sonata-project/SonataFormatterBundle/pull/235/commits/6f528100276b6508fbceddb9127cc5c9e28d3bad

core23 commented 7 years ago

Could you provide a PR with a fix @ersah123