pogidude Posted June 19, 2013 Share Posted June 19, 2013 Attached is my module file PageEditPerRole.module So, you go to a role and add pages that a user with that role can edit and add pages to. Now, the problem starts when user creates a page. It will look like this: No templates in the dropdown. That's because of this lines of code in the ProcessPageAdd::getAllowedTemplates() method: if($this->parent->is(Page::statusUnpublished)) { $parentEditable = $this->parent->editable(); } else { // temporarily put the parent in an unpublished status so that we can check it from // the proper context: when page-publish permission exists, a page not not editable // if a user doesn't have page-publish permission to it, even though it may still // be editable if it was unpublished. $this->parent->addStatus(Page::statusUnpublished); $parentEditable = $this->parent->editable(); $this->parent->removeStatus(Page::statusUnpublished); } foreach($this->fuel('templates') as $t) { if($t->noParents) continue; if($t->useRoles && !$user->hasPermission('page-create', $t)) continue; if(!$t->useRoles && !$parentEditable) continue; if(!$t->useRoles && !$user->hasPermission('page-create', $this->parent)) continue; I've highlighted the relevant lines. Now here's the weird part. I added the following lines of code just right before the code above somewhere in line #100 foreach($this->user->roles as $r){ if(count($r->role_editable_pages)){ error_log('=== #pages: '.count($r->role_editable_pages). ' template: '.$r->name); foreach($r->role_editable_pages as $e){ error_log('===== page name: '.$e->name); } } } and here's what you get: what is going on here? Here's the ProcessPageAdd.php file I hacked from core ProcessPageAdd.module Link to comment Share on other sites More sharing options...
ryan Posted June 20, 2013 Share Posted June 20, 2013 I'm using the default theme, so not positive what method it's using to show you 'latest updates'. But assuming it's showing pages with the most recent 'modified' date, chances are that some module hook somewhere updated that page. Either that, or it's limiting them to a specific time and you fell in that time one time and not another. This may be a question for that theme's thread. Link to comment Share on other sites More sharing options...
pogidude Posted June 20, 2013 Author Share Posted June 20, 2013 actually, the issue here is basically what I started on this thread http://processwire.com/talk/topic/3855-pagearray-field-in-a-role-doesnt-have-anything-when-adding-a-page/ I didn't know they were related at that time thus the separate thread. As you can see from this reply I made and comparing it to my reply above, what I'm pointing out is that the template dropdown *worked* when I added this: foreach($this->user->roles as $r){ if(count($r->role_editable_pages)){ error_log('=== #pages: '.count($r->role_editable_pages). ' template: '.$r->name); foreach($r->role_editable_pages as $e){ error_log('===== page name: '.$e->name); } } } which is now the foreach line I now use in my module foreach($this->user->roles as $r){ $r->role_editable_pages; } 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