0
votes

I'm working on a symfony2 project using sonata admin bundle. I have some editable text on my website like "presentation" "actually" etc...

I found a solution but it does not feel like its the good way to do.

I've created an Entity EditableText where I map a key with a content like :

key => "presentation" content => "this is my presentation"

and I do the same for all of my EditableText.

Doing it this way leads me to a list of EditableText in my sonata admin bundle which is not "user friendly" for a non tech guy. If he removes a row, the website can't find the content ... etc ...

I would like to have in sonata a field where the user can edit each texts somewhere, but cannot modify they key or delete a row or something.

I don't mind changing my conception.

If you have any tips, suggestions, ...

Thanks and sorry for my english ;)

1
Maybe a little more context into why there's a key store entity to edit (seemingly?) single-word text? If it's translations, that's one thing. If it's settings, a Yaml treatment might be appropriate. Or an entity (maybe?) might be appropriate. Performance-wise, it doesn't seem like a great idea to put little single-word text snippets in their own row in a database, although again I don't know the implementation. - Jared Farrish
Ok I'll try. My website is composed by some texts like my presentation, what I'm actually working on, etc ... . I want these texts to be editable in sonata admin bundle. I've created an entity called EditableText(string key, string content) where I put as a key "presentation" and as a content "my text of presentation blablabla". Then in my controller I ask the database for the EditableText which has the "presentation" key and I get the content, and then I can load it - pcavalet

1 Answers

1
votes

If you want to keep your concept you can restrict access for an editor by using a role based security approach. You could grant the editor just the ROLES LIST, VIEW, EDIT as described in the security section of the SonataAdminBundle documentation. This way the admin (you) can create the entities with the needed keys for your website and the editor could view and update them.

As an example: when you have defined your admin service as sonata.admin.editable_text

you have to assign the roles

  • ROLE_SONATA_ADMIN_EDITABLE_TEXT_LIST
  • ROLE_SONATA_ADMIN_EDITABLE_TEXT_VIEW
  • and ROLE_SONATA_ADMIN_EDITABLE_TEXT_EDIT

You could than easily group these roles into one role using the role_hierarchy directive of the security configuration:

security:
# ...
role_hierarchy:

    # group the roles for your convenience, 
    ROLE_SONATA_EDITOR:
        - ROLE_SONATA_ADMIN_EDITABLE_TEXT_LIST
        - ROLE_SONATA_ADMIN_EDITABLE_TEXT_VIEW
        - ROLE_SONATA_ADMIN_EDITABLE_TEXT_EDIT