Joe Posted November 16, 2013 Share Posted November 16, 2013 Hi all! I´m wondering how I can limit the amount of pages that can be added to a site. For example, I might want to limit the number of pages on the top navigation level to 10 (to not allow the menu to become too wide) and the number of child pages that can be added to 6 for each top level page. Looking here in the forum I haven´t seen anything on this, might have missed it. I suppose the way to go about it is to only allow a certain number of pages to be created per template. Do I have to write some php function that counts the pages and then limits what can be done in the admin default.php or am I missing something and there is a setting somewhere that will do this? Thank you! Link to comment Share on other sites More sharing options...
teppo Posted November 16, 2013 Share Posted November 16, 2013 First of all, there's one issue page limit won't solve: you'd also have to limit page name (or whatever you're using in your top level navigation) to make this even remotely useful. Otherwise users could simply create pages with names long enough to break your navigation anyway Template approach would be feasible only if you want to limit pages on your top navigation but not after that. Otherwise you'd run into huge problems, such as having to create new template for children of each top level page (and another for each of their children etc.) It would make more sense to enforce a child limit for each (direct) parent page. The way I'd probably start digging into this would be by creating a module that hooks into ProcessPageAdd execute() method and adds additional check, either based on some hard-coded limit or a value of a field in some custom-created setup page (or a custom setting in site config, whichever you prefer) to see if a page can be added below given parent based on the number of existing children. Problem with that approach is that you'd also have to prevent user from moving pages in some situations, or they could simply avoid this limit by creating page elsewhere and then moving it where they want it. This could probably be solved by hooking into Pages save() method, but that would be somewhat ugly; giving user some kind of clue about this limit within UI (i.e. before they attempt to move a page) would be optimal, but I'm not quite sure how to achieve that without a lot of custom code. Hope this helps a bit. If you want to do this properly, it'll require some work, and personally I don't think it would still be optimal solution.. but that's just my opinion 3 Link to comment Share on other sites More sharing options...
Joe Posted November 16, 2013 Author Share Posted November 16, 2013 Thank you, teppo First of all, there's one issue page limit won't solve: you'd also have to limit page name (or whatever you're using in your top level navigation) to make this even remotely useful. Otherwise users could simply create pages with names long enough to break your navigation anyway Yes, I´ve already resolved this by limiting the number of characters that can be used in the new page names input field and by using a fixed width font for the menu. Template approach would be feasible only if you want to limit pages on your top navigation but not after that. Otherwise you'd run into huge problems, such as having to create new template for children of each top level page (and another for each of their children etc.) It would make more sense to enforce a child limit for each (direct) parent page. So I could enforce a child limit for the home page template of 10 in this case and for the rest of the templates set the child limit to 6. That would then take care of the limit of 10 for the top level and 6 for the rest of the pages as in the example above. I think the problems you mention will only arise on larger sites, not if I wanted to only have the limit as per above, with no further children allowed? Link to comment Share on other sites More sharing options...
teppo Posted November 17, 2013 Share Posted November 17, 2013 Joe, I think I read your original post slightly wrong; I thought you meant that there would be a limit on how many pages can be created with each template -- while you probably meant a limit on how many children could each page with given template have. Considering this you can pretty much forget that template part in my first reply.. Also, I said that in ProcessPageAdd you could use "some hard-coded limit or a value of a field in some custom-created setup page (or a custom setting in site config, whichever you prefer) to see if a page can be added below given parent based on the number of existing children." If I'm reading your post correctly now, you'd find the template of the parent page of the page currently being added and get that limit from there, then count existing children for that parent and only then add the page. Makes sense, actually. One more thing I forgot to add to my original reply is that even if you checked in ProcessPageAdd if a page could be added, you'd still definitely want to add additional check at Pages save() just to make sure that two users weren't adding pages at the same time via ProcessPageAdd.. 4 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now