Search code examples
phpsymfonyckeditorsonata-adminsonata

How to separate folders using IvoryCKEditorBundle for file uploads?


I'm using the following in my project:

  • Symfony 2.3
  • IvoryCKEditorBundle
  • CoopTilleulsCKEditorSonataMediaBundle

My intention is that users can create their own pages for showing different types of information. However, users are separated by a certain kind of relationship (certain users belong to a certain school, so only users from that school should be able to see files said school uploaded and no one else). I know literally nothing about the Sonata Media Bundle or the Sonata Project in particular, I'm on a time constraint and the docs are just too much for me to handle in a short time. I somehow managed to install the Media Bundle, and even that took a full day, which was spent figuring out the dependencies to make it work.

So I come to you. When I try to upload a file, I get the following error:

 Key "provider" for array with keys "context, category, hide_context" does not exist in CoopTilleulsCKEditorSonataMediaBundle:MediaAdmin:browser.html.twig at line 47 

I haven't configured the admin class, and I don't even know why do I have to configure it and how I'm supposed to integrate it with my current model. So my questions are:

  • Why does that error happen?
  • Why do I need to configure an admin class? Doesn't the AdminBundle comes with its own basic admin class?
  • How do I separate users, so that each can only see the stuff uploaded for their school and no more?

Thank you for your time.


Solution

  • This error is due to a change in the way MediaBundle works. In order to get it solved you have to go to the browser.html.twig and replace lines 46 to 58 by this:

    {% if (persistent_parameters.provider is defined) and ( not persistent_parameters.provider) %}
                            <li class="active"><a href="{{ admin.generateUrl('browser', {'context': persistent_parameters.context, 'provider': null}|merge(ckParameters)) }}">{{ "link.all_providers"|trans({}, 'SonataMediaBundle') }}</a></li>
                        {% else %}
                            <li><a href="{{ admin.generateUrl('browser', {'context': persistent_parameters.context, 'provider': null}|merge(ckParameters)) }}">{{ "link.all_providers"|trans({}, 'SonataMediaBundle') }}</a></li>
                        {% endif %}
    
                        {% for provider_name in providers %}
                            {% if (persistent_parameters.provider is defined) and (persistent_parameters.provider == provider_name) %}
                                <li class="active"><a href="{{ admin.generateUrl('browser', {'context': persistent_parameters.context, 'provider': provider_name}|merge(ckParameters)) }}">{{ provider_name|trans({}, 'SonataMediaBundle') }}</a></li>
                            {% else %}
                                <li><a href="{{ admin.generateUrl('browser', {'context': persistent_parameters.context, 'provider': provider_name}|merge(ckParameters)) }}">{{ provider_name|trans({}, 'SonataMediaBundle') }}</a></li>
                            {% endif %}
                        {% endfor %}
    

    Hope this helps you