Jump to content

how to manage Delete Tab for user groups


mrkhan
 Share

Recommended Posts

Hello,

i have completed my first project in PW and its really great. i have few user groups and i want to give delete page options for each group on Template basis.

i don't want to give all templates delete options to some group but want to hide Delete tab for some templates and show delete tab for some templates.

like if i have two templates

1. products
2. product

i want that user can see delete tab on product template but not on products template.

how can i do that ?

Thanks

Link to comment
Share on other sites

Search the forum via google give's in most cases a better result - while the forum search lack a bit...;)

here some hints and links on this topic:

https://processwire.com/talk/topic/4680-block-access-to-settings-delete-and-view-tabs-for-page/

https://processwire.com/talk/topic/3159-hide-settings-tab-in-page-edition/

best regards mr-fan

Link to comment
Share on other sites

Had to do this yesterday. But this works only on the newest dev version of processwire, because Ryan just implemented the removeTab() method. Older versions will still show the tab, but no actual form to delete something.

<?php

/**
 * ProcessWire 'Hello world' demonstration module
 * 
 * ProcessWire 2.x 
 * Copyright (C) 2014 by Ryan Cramer 
 * Licensed under GNU/GPL v2, see LICENSE.TXT
 * 
 * http://processwire.com
 *
 */

class RemoveDeleteTab extends WireData implements Module {

	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
	 *
	 * @return array
	 *
	 */
	public static function getModuleInfo() {

		return array(
			'title' => 'RemoveDeleteTab', 
			'version' => 1, 
			'summary' => '…',
			'singular' => true, 
			'autoload' => true,
			);
	}

	public function init() {
		// Remove Settings Tab in Global settings for non superadmins
		$this->addHookAfter('ProcessPageEdit::buildForm', $this, "removeDeleteTab");
	}

	public function removeDeleteTab(HookEvent $event){
		// check what role the user has, if superuser do nothing
		if($this->user->isSuperuser()) return;

		$page = $event->object->getPage();

		if($page->template->name === "settings"){
			$form = $event->return;

			$fieldset = $form->find("id=ProcessPageEditDelete")->first();
			$form->remove($fieldset);
			$event->object->removeTab("ProcessPageEditDelete");

      $event->return = $form;
		}
	}
	
}

  • Like 4
Link to comment
Share on other sites

Hello

when i use your module i got following error

Error: Class 'RemoveDeleteTab' not found (line 316 of /Applications/XAMPP/xamppfiles/htdocs/web1/wire/core/Modules.php) 
This error message was shown because you are logged in as a Superuser. Error has been logged.

i have downloaded current PW 2.5 and its still same.

Link to comment
Share on other sites

let me explain you what i did and what is error , i have downloaded new version of PW 2.5 and install it. it was working perfect.

1. create a new folder name "RemoveDeleteTab" in site ->module directory

2. create a file "RemoveDeleteTab.module"

3. put you code in "RemoveDeleteTab.module" file

and when i goto admin and try to install this module i got bellow error

Recoverable Fatal Error: Argument 1 passed to RemoveDeleteTab::removeDeleteTab() must be an instance of HookEvent, none given, called in /Applications/XAMPP/xamppfiles/htdocs/web1/wire/core/Modules.php on line 316 and defined (line 23 of /Applications/XAMPP/xamppfiles/htdocs/web1/site/modules/RemoveDeleteTab/RemoveDeleteTab.module) 
This error message was shown because you are logged in as a Superuser. Error has been logged.
Link to comment
Share on other sites

Here a gues:

It's weird that the name of the method is the same as the class. With the same name it will act as a constructor and thus has no HookEvent. (not sure it is as your classname is capitalized) Could you rename removeDeleteTab method to afterRemoveDeleteTab (or something you wish)

Link to comment
Share on other sites

Hello LostKobrakai,

can you please tell me what is current development version ?

as i can get is 2.5.2, what is current development version and how to get it, if you please share the link?

@Martijn Geerts i also try to rename the  removeDeleteTab method to afterRemoveDeleteTab but it did't work...

Thanks

Link to comment
Share on other sites

Hello 

i find the new DEV version i got it working when i rename the function to 

public function afterRemoveDeleteTab(HookEvent $event){

and also change this function too

public function init() {
// Remove Settings Tab in Global settings for non superadmins
$this->addHookAfter('ProcessPageEdit::buildForm', $this, "afterRemoveDeleteTab");
}

as @Martijn Geerts  suggested Thanks @Martijn Geerts 

But how to hide SETTINGS and Delete tabs for some Templates not all ?

once its done i will share all module with every one as i think most of users need this option in admin.

Thanks

Link to comment
Share on other sites

Have a look at what the function actually does. It's looking if the template of the current page is named "settings", so this only removes the delete tab for the "settings" template. Change this to fit your purposes. For the settings tab, there's also a Fieldset "ProcessPageEditSettings" with a tab also named "ProcessPageEditSettings". Remove them in the same fashion as the "ProcessPageEditDelete".

Link to comment
Share on other sites

Oh Perfect it works fine now :) , here is code & module 

1. use the latest version of PW

2. create a folder name "RemoveDeleteTab" in your site/modules/RemoveDeleteTab

3. create a module file "RemoveDeleteTab.module" in site/modules/RemoveDeleteTab

4. bellow is code for module and it will work perfect, enjoy :)

<?php
class RemoveDeleteTab extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => 'RemoveDeleteTab', 
'version' => 1, 
'summary' => 'Remove Delete Tabs for Some Users & Some Templates',
'singular' => true, 
'autoload' => true,
'icon' => 'smile-o', 
);
}

public function init() {
// Remove Settings Tab in Global settings for non super admins
$this->addHookAfter('ProcessPageEdit::buildForm', $this, "afterRemoveDeleteTab");
}

public function afterRemoveDeleteTab(HookEvent $event){
// check what role the user has, if superuser do nothing
if($this->user->isSuperuser()) return;

$page = $event->object->getPage();

/// products is a template name , you can use your own template name here
if($page->template->name === "products"){
$form = $event->return;

//remove settings tab
$fieldset = $form->find("id=ProcessPageEditSettings")->first();
$form->remove($fieldset);
$event->object->removeTab("ProcessPageEditSettings");

//remove delete tab
$fieldset = $form->find("id=ProcessPageEditDelete")->first();
$form->remove($fieldset);
$event->object->removeTab("ProcessPageEditDelete");

 $event->return = $form;
}
}
}

now Install the Module and it will work.

thanks to @LostKobrakai and @Martijn Geerts

  • Like 2
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

×
×
  • Create New...