LyraAdminBundle
LyraAdminBundle copied to clipboard
Child admin panels - Is it supported/planned?
Classic example is Post one-to-many Comment, or Product one-to-many ProductOption.
I am in the Post list panel, I select a post to edit, and I go to the edit post panel. Now I want an easy way to add comments to this post, see all comments for this post, etc. (list/sort/filter them), and generally manage them.
If I didn't have a child admin, I'd have to go to the comments list panel and filter by post. To add a comment to a post, I'd have to add a new comment, select the post from a dropdown and save.
The advantage of a child admin is I don't have to go to the Comments panel and filter by post.name to see all comments for the Post, I can see that by clicking a link on the Post panel.
But more importantly, to add a comment to my post, I click Comments ( a link on the Post edit screen). This shows me the comments for my post only. Then I click add to add a new comment. When I save, it is automatically added to my post.
This is currently not possible by only setting some configuration options. It can be done with a custom object action on posts list to show all comments of that post, a custom manager for the comment model that overrides the getBaseListQueryBuilder() method to restrict the list to comments of a given post and maybe a couple of more hacks :) I can try to provide an example.
If you were going to incorporate something like that, I suppose the best way to do it might be through the url.
ie. you add a link to the side of the Post show/edit screen called Comments. It would be the link for the Post edit url, and at the end of the url, you would add something like (sorry I'm not familiar with your url structure) :
to list comments for a post: #3: posts/show/3/comments to add a comment for post #3: posts/show/3/comments/add to edit comment #10 for post #3: posts/show/3/comments/edit/10
The manager which handles the list/add/edit would just need to be modified to look at the url to see if it needs to restrict the display of comments to a particular post (in the list), or whether it needs to assign the comment to a particular post (in the add/edit).
This can be written generically into the model manager so that it would even work 2 or more levels down.
eg. Hotel one-to-many Room one-to-many Season one-to-many Rate
Whenever it is called to list it's model objects, it checks the url to see if it should restrict the display to some "parent".
In the config, for a given entity, you would list which "child models" you wanted it to display links for on the show page.
Just some food for thought.
MGIBlogBundle shows how this scenario can be managed with the current version of LyraAdminBundle. A button Comments
(displayed both on posts list and at the top of the post edit form) shows the comment list pre-filtered to show only comments of that post. When a new comment is added and this filter is active, the post drop down list on the comment create form shows by default the 'current' post.
It's not possible to manage everything through configuration options because code is needed to manage an extra action and to customize newAction() in comment controller.
This is what it's available right now, future improvements are always possible.
Sounds good.
You might take it one small step further, and in the Comment add/edit, make the dropdown (set to the current Post) hidden when this admin is acting as a "child".
Same with the filter - on the Comment listing, when Comments is acting as a child of Post, make the Post filter hidden (with it's value set to the parent post).