ryancramerdesign / ProcessWire

Our repository has moved to https://github.com/processwire – please head there for the latest version.
https://processwire.com
Other
727 stars 201 forks source link

AdminThemeDefaultHelpers::renderTopNavItems #1344

Open Da-Fecto opened 9 years ago

Da-Fecto commented 9 years ago

HI Ryan, can you make AdminThemeDefaultHelpers::renderTopNavItems hookable? I have a need to hide the "Pages" page from the TopNavItems when not logged in as superuser. Or maybe even better:

/**
 * Render all top navigation items, ready to populate in ul#topnav
 * 
 * @param PageArray|array $exclude_pages Pages to exclude from topnav
 * @return string
 *
 */
public function ___renderTopNavItems($exclude_pages = array() ) {
    // .... some code to exclude $exclude_pages from top nav.
}

So a before hook has the opportunity to modify the arguments so pages can be excluded. Thanks !

Da-Fecto commented 9 years ago

I didn't recognise that for theme Reno there's an other class and an other method for this. So next to the AdminThemeDefaultHelpers::renderTopNavItems it would be great to have AdminThemeRenoHelpers::renderSideNavItems also hookable. Something like:

public function ___renderSideNavItems($exclude_pages = array()) { ... }
ryancramerdesign commented 9 years ago

No problem making things hookable, but seems like this is a permissions need rather than a markup one. Wouldn't it be better to hook Page::viewable? Perhaps something like this in your /site/templates/admin.php file:

if(!$user->isSuperuser()) wire()->addHookAfter('Page::viewable', function($event) {
  if($event->object->id == 3) $event->return = false; // 3 is id of /processwire/page/
}
Da-Fecto commented 9 years ago

I thought of that and have tried it but didn't work out because of the check_access=0 in the selector I guess. (or some other things I don't be aware of)

On the otherhand there are more things in the masthead that I don't wish for this project such as the view button. (Project doesn't need to have a front-end)

wanze commented 9 years ago

+1 for making this method hookable, so we can also add new entries. Also it would be nice if the RenoAdminTheme could use the same method for rendering the main menu items, so that hooks persist when changing admin themes. Not sure how easy this would be... maybe let AdminThemeRenoHelpers extend AdminThemeDefaultHelpers and then hook after AdminThemeDefault::renderTopNavItems(), which then probably should be renamed to something like renderNavItems() :)

Da-Fecto commented 9 years ago

It was stupidity on my side about the permission, your solution works. On the other hand I still have the need to change the markup anyway so the question is still open.

And +1 for what wanze suggests about the naming convention.

rolandtoth commented 8 years ago

It would be great if they were hookable. Currently I need to use additional JavaScript to put my custom items in their place wich is not the prettiest thing.