Jump to content

ProcessPageAdd::getAllowedTemplates() weird...


pogidude
 Share

Recommended Posts

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:

post-1067-0-83550500-1371610499_thumb.pn

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:

post-1067-0-42585100-1371611001_thumb.pn

what is going on here?

Here's the ProcessPageAdd.php file I hacked from core ProcessPageAdd.module

Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...