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

[PagepartBundle]: Possibility for nested pageparts #1174

Closed
Perni1984 opened this issue May 26, 2016 · 13 comments
Closed

[PagepartBundle]: Possibility for nested pageparts #1174

Perni1984 opened this issue May 26, 2016 · 13 comments

Comments

@Perni1984
Copy link

For a project I would need the possibility to nest pageparts within pageparts. Is this currently possible?

What I am trying to achieve is e.g. adding a two-column pagepart, where I have some pageparts in the first column and other pageparts in the second - or adding a three-column pagepart, where I can add different pageparts to the columns. Eventually there would be another way to do this (e.g. without nested pageparts). Any help would be appreciated.

@Perni1984
Copy link
Author

from a quick look I guess the same functionality can be achieved, when the backend allows dynamic adding/removing regions. Is this correct? Is this functionality available already?

@Perni1984
Copy link
Author

ping @mlebkowski: I saw that you are already experienced with nesting forms - maybe you would have a hint for me about how to best achieve that.

@jockri
Copy link
Contributor

jockri commented May 30, 2016

Can this be useful for your use case?
https://bundles.kunstmaan.be/news/using-sub-entities-in-pageparts

@Perni1984
Copy link
Author

@jockri: thanks for pointing this one out.

I already thought about that, but as far as I understood all Entities that are in the ArrayCollection must have the same type. This could be the case if I use an ArrayCollection of e.g. AbstractPagePart or and then render the form of the type that inherits AbstractPagePart.

The only problem I have is, that I don't know how to do that?

I have been googling around seeing some ideas of adding polymorphism to symfony's underlying form system - https://github.com/infinite-networks/InfiniteFormBundle - but I am not sure if this is not over the top and I really don't want to introduce the complexity of an additional bundle, to the already somewhat complex forms system.

There is I guess also the possiblity to dynamically enhance the forms via Form Events:
http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html#cookbook-form-events-submitted-data

But I am not sure which route to go - maybe someone of Kunstmaan has the right hint what to do. Basically I think it is the same mechanism that you already implemented with "add a Pagepart" in a certain region of a page, but instead you add it as a child to a collection of a form.

@Perni1984
Copy link
Author

some more info on polymorphic collections can be found here:
symfony/symfony#9835

@mlebkowski
Copy link
Contributor

Yeah, I don’t think I can really help you, but I can give some suggestions.

For starters, saving those entities would be done in a similar way that current page parts are — using a page_part_refs kind of table. But the interface would be complicated. It’s not only a nested form, but also you’d have to choose what kind of a page part you’d like to add. With this in mind it would be better to use the current page part system.

I don’t know the full requirements of your project, but it seems that it would be easier to add a Tab with regions configuration (this could be a simple nested form with a Column-ish configuration). Then, using the PageTemplateReader I added in #1109 you could use this configuration to prepare a dynamic template for your page, extending eiter PageTemplateConfigurationReader or PageTemplateConfigurationParser.

The system would consist of:

  • A custom template configuration for your „dynamic template”, let’s name it "dynamic". It would have one region (a „column”) with some page part types, but it would be later converted to a set of columns
  • A Page Tab module, with an adaptor, listener, form, some entities, etc. It would be shown only if the page’s template is set to „dynamic” and its role would be to change the number of columns
  • The Template Parser/Reader that would build the template configuration for each page with the „dynamic” template using the entities / data saved in the Page Tab. This way the „dynamic” template with a "column" region would be changed to a set of regions: "column_1", "column_2", etc.

Does this seem right for you?

@Perni1984
Copy link
Author

Perni1984 commented Jun 6, 2016

@mlebkowski: Thanks a lot for your suggestions!

After fiddling around with polycollection and not being very succesfull at adapting the pagepart system to the polycollection forms I started to create my own PageTemplate Parser/Reader to explore this idea. I managed to created Regions inside Regions, with this "pseudocode":

 /** class MyPageTemplateConfigurationParser extends PageTemplateConfigurationParser **/
...
 public function parse($name) {
 ...
 $rawData = [
            'name' => 'Content page',
            'template' => 'MyAppBundle::Pages\ContentPage\pagetemplate.html.twig',
            'rows' => [
                [
                    'regions' => [
                        [
                            'name' => 'main_left',
                            'span' => 4,
                            'regions' => [
                                [
                                    'span' => 6,
                                    'name' => 'main_left_sub1',
                                ],
                                [
                                    'span' => 6,
                                    'name' => 'main_left_sub2',
                                ]
                            ],
                        ],
                        [
                            'span' => 4,
                            'name' => 'main'
                        ],
                        [
                            'span' => 4,
                            'name' => 'main_right'
                        ]
                    ]
                ]
            ]
        ];

I am succesfully displaying the following regions in the Backend-Admin:

  • main_left_sub1
  • main_left_sub2
  • main
  • main_right

But unfortunately main_left is not displaying, as it is the region that is holding the child regions.

I am already overwriting the process_region method in PageTemplateWidget ensuring that also the widget of main_left is loaded, which it is, but I have not managed to get it displayed in the backend:

image

image

Do you have any ideas on that?

@mlebkowski
Copy link
Contributor

You’d like to have the main_left region with pageparts as well? Or are you just talking about displaying a container to group the sub-regions together?

@Perni1984
Copy link
Author

I would like to have the main_left region with pageparts aswell.

@mlebkowski
Copy link
Contributor

Well, look into your template / renderer code. You must have some kind of condition on those sub-regions to display them instead of the main region. Anyway, this is your turf now, good luck ;)

If I had to do it, I wouldn’t use columns for main regions (left / center / right), but rows instead. It would be cleaner for me this way:

left sidebar main content
left column 1 left column 2
center main content
right main content

@Perni1984
Copy link
Author

@mlebkowski: Thanks a lot for your help you already pointed me in the right direction! I will try to debug the problem better.

@Perni1984
Copy link
Author

Actually I found the bug/feature now. The template that is delivered for PageTemplateWidget in the Kunstmaan PagePartBundle doesn't render the pageparts for the parent - only for the children.

You can alter this behaviour by rewriting the render_region macro in PagePartBundle\Resources\views\FormWidgets\PageTemplateWidget\widget.html.twig

@mlebkowski: again, thanks a lot for your help.

@Perni1984
Copy link
Author

I managed to dynamically implement an arbitrary number of Rows/Regions per Page that are read out of the database by writing my own implementation of PagePartConfigurationReader and PagePartTemplateConfigurationReader.

@mlebkowski: thanks for your PR #1109, without it this would not have been possible so easy.

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