Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not work with Sonata Admin #68

Closed
sivinnguyen opened this issue Dec 20, 2012 · 4 comments
Closed

Not work with Sonata Admin #68

sivinnguyen opened this issue Dec 20, 2012 · 4 comments

Comments

@sivinnguyen
Copy link

I followed the instruction but it doesn't work

My configuration:

stfalcon_tinymce:
    include_jquery: true
    tinymce_jquery: true

My form builder

   protected function configureFormFields(FormMapper $formMapper)
       {
           $formMapper  
                    ->add('content', 'textarea', array(
                        'attr' => array(
                            'class' => 'tinymce',
                            'data-theme' => 'medium' // simple, advanced, bbcode
                           )
                    ))
            ;
      }

Nothing happen. Thanks!!!

@fluxuator
Copy link
Contributor

Hi @sivinnguyen. To initialize TinyMCE bundle in Sonata, you should, for example, override one of Sonata bundle's template:

Create file /app/Resources/SonataAdminBundle/views/CRUD/edit.html.twig with code:

{% extends 'SonataAdminBundle:CRUD:base_edit.html.twig' %}
{% block javascripts %}
    {{ parent() }}
    {{ tinymce_init() }}
{%endblock%}

@sivinnguyen
Copy link
Author

I get this error

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 130968 bytes) in /vendor/symfony/symfony/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php on line 134

@sivinnguyen
Copy link
Author

It works now. Thanks so much!

@Entamut
Copy link

Entamut commented Dec 2, 2019

Hi,

This is just for those of you that landed here not knowing how to setup SonataAdmin and Tiny MCE (and don't want to spend time trying to make it work as I did ;) ).

I got it working (Symfony 4.2 + SonataAdmin Bundle 3.55.0 + stfalcon/tinymce-bundle 2.0.4) following these steps:

  1. Assuming all Sonata stuff is ready and working:
composer require stfalcon/tinymce-bundle
  1. Ensure one of your textarea fields is added to one of your forms in your admin controller (this is sonata related and you should already know where this goes ;) ):
// src/Admin/MyentityAdmin.php
protected function configureFormFields(FormMapper $formMapper)
{
  $formMapper->add('myTextArea', TextareaType::class, ['attr' => ['class' => 'tinymce']])
}
  1. Extend SonataAdmin edit template by creating a new template (path and name is up to you):
{# templates/Admin/CRUD/edit.html.twig #}
{% extends '@SonataAdmin/CRUD/edit.html.twig' %}

{% block javascripts %}
    {{ parent() }}
    {{ tinymce_init() }}
{% endblock %}
  1. Tell SonataAdmin to use your extended template instead of default one:
# config/packages/sonata_admin.yaml
sonata_admin:
  templates:
    edit: 'Admin/CRUD/edit.html.twig'

Hope it works.

Other questions:

  • Should I include the include_jquery and tinymce_jquery parameters? If you are loading jQuery already then I think you should not (not sure about multiple versions issues ;) ).
  • Where should I put the include_jquery and tinymce_jquery parameters? You can put those in services.yaml, but I think it would be better to have a separate file (i.e. stfalcon.yaml).

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants