adrian

Restrict Tab View

Recommended Posts

Hey @valan - sorry about that - it was a bug in Hide mode. I just committed a new version that should fix things for you.

  • Like 3

Share this post


Link to post
Share on other sites

@arjen: why don't just hide them using custom css and admincustomfiles module?

Hey Nico, sorry for responding late. Been on a long, long holiday. This is off course another option which I've used in the past too. Thanks for adding.

Share this post


Link to post
Share on other sites

@arjen: FYI and possible fix - since upgrade to PW 2.6.10 in some cases module throws error "Call to a member function attr() on a non-object (line 245 of /var/www/pw/wire/core/InputfieldWrapper.php)". Playing with settings I've mentioned that it happens when I check tab-children-hide for user that gets this error. There were major permission system updates in PW 2.6.10 so I guess new core may conflict with module somehow.

EDIT: Continued experiments and found that tab-settings-hide causes this error when trying to edit user page. Also tab-delete-hide does not function at user page. E.g. clearly there are some conflicts btw PW 2.6.10 and this module.

Share this post


Link to post
Share on other sites

@arjen: FYI and possible fix - since upgrade to PW 2.6.10 in some cases module throws error "Call to a member function attr() on a non-object (line 245 of /var/www/pw/wire/core/InputfieldWrapper.php)". Playing with settings I've mentioned that it happens when I check tab-children-hide for user that gets this error. There were major permission system updates in PW 2.6.10 so I guess new core may conflict with module somehow.

I assume this was directed at me, and not @arjen?

I am trying to replicate your issue here but can't at the moment. Just quickly, I am wondering if that might be a bug in InputfieldWrapper.php

Could you please try to replace that line 245:

} if($this->getChildByName($item->attr('name')) && $item->parent) {

with:

} elseif($this->getChildByName($item->attr('name')) && $item->parent) {

I am not sure this is the problem, but it's weird to me the styling Ryan has with the "if" starting on the same line as the closing curly brace, so I think it might be meant to be an "elseif".

Anyway, let me know if that fixes things - if not can you narrow down a particular setup that results in the new error.

Share this post


Link to post
Share on other sites

@adrian, ups, yes this is directed to you.)

Replaced, but it does not fix a problem.(

Particular setup:

- module is installed with checked Hide "children, settings, delete" in settings

- there is user X with role "content-editor".

- when role "content-editor" has only "tab-settings-hide" and "tab-delete-hide" permissions - everything is OK, e.g. no any tabs in the page (btw children tab is also hidden)

- when role "content-editor" has also "tab-children-hide" permission => error above

 
Again, this happened in PW 2.6.10 dev - could be either result of permission system changes or simply dev bugs... Anyway, looks like this code may not setup $fieldset in some cases:
 
        if($tab == "Settings" || $tab == "Children") {
            $fieldset = $form->find("id=ProcessPageEdit".$tab)->first();
        }
        else {
            $fieldset = $form->find("id=ProcessPageEdit".$tab);
        }

P.S. The same error is thrown in another scenario - when editing "user" page by different user/role. But now issue is with "tab-settings-hide" only...

P.S. Just idea - may be some tabs in some cases can't be found with $form->find? E.g. for example when user does not have access to add children (restricted at template level) then Children tab is not displayed. 

EDIT: Temporarily made quickfix after if-else block above: if (!is_object($fieldset)) return;

It prevents errors - module works as expected at all pages. Except "user" page - here "delete" tab does not disappear (while "tab-delete-hide is ON"), but "children" tab disappears ("tab-children-hide" is ON too).

  • Like 1

Share this post


Link to post
Share on other sites

@valan - thank you for helping to figure this out. I added your is_object check and also fixed the issue with the Delete tab not being hidden. 

Could you please try the new version and let me know if everything is working as expected?

Share this post


Link to post
Share on other sites

@adrian - this is to confirm that now it works as expected. Thank you for this module!

  • Like 1

Share this post


Link to post
Share on other sites

Module should add additional permissions automatically.

For most modules, I would agree with you, but this one potentially has 8 custom permissions. I think most users will probably only want the "tab-settings-view" or "tab-settings-hide" permission. I'd rather not pollute the permissions list with 7 additional unnecessary permissions if you are planning on only using one.

Do you see my point?

  • Like 3

Share this post


Link to post
Share on other sites

Maybe the "new" permission suggestion screen, which ryan implemented for the various optional core permissions, could also hold optional module permissions.

  • Like 3

Share this post


Link to post
Share on other sites

Not sure if this one is connected with the module directly, but still...

Is there an easy way to hide the Content tab if all the other tabs are disabled with permissions?

Share this post


Link to post
Share on other sites
1 hour ago, Ivan Gretsky said:

Not sure if this one is connected with the module directly, but still...

Is there an easy way to hide the Content tab if all the other tabs are disabled with permissions?

Hi Ivan - not sure I am understanding - do you want to hide all tabs, or do you have some custom fieldsettabs that would still be displayed? I could perhaps implement, but if it's a case of just not wanting a tab named "Content", don't forget that you can actually rename this.

Does that help, or am I not understanding your scenario?

Share this post


Link to post
Share on other sites

I got all tabs but Content turned off. So the lonely Content Tab seems unnecessary and confusing. I thought that it would be better to see no tabs at all when only one is present. I know I can rename it, but that hardly makes it look any better. I surely can live with this tab, just wanted to know if there is an easy workaround.

Share this post


Link to post
Share on other sites

So you want the fields from the content tab to still be there, just not the tab "button" (for want of a better description)?

That sounds more like a job for CustomAdminFiles or maybe a feature request for AOS?

This module hides entire tabs, including their content.

Am I on the right track now?

 

  • Like 1

Share this post


Link to post
Share on other sites
1 minute ago, PWaddict said:

I've just installed the module. Isn't possible to hide the children tab ONLY on a specific template?

Currently no, the module is designed for site-wide use, but you could extend it to have a template selector in the module config, or just steal the relevant code from the module and add it as a hook in your /site/ready.php file.

  • Like 1

Share this post


Link to post
Share on other sites
58 minutes ago, adrian said:

Currently no, the module is designed for site-wide use, but you could extend it to have a template selector in the module config, or just steal the relevant code from the module and add it as a hook in your /site/ready.php file.

Ok I hide the children tab on the template I wanted but now the order of tabs is changed on the other templates. It shows them in this order: Content, Settings, Delete, View, Children instead of Content, Children, Settings, Delete, View. I'm not sure how can I fix that.

Share this post


Link to post
Share on other sites
2 minutes ago, PWaddict said:

Ok I hide the children tab on the template I wanted but now the order of tabs is changed on the other templates. It shows them in this order: Content, Settings, Delete, View, Children instead of Content, Children, Settings, Delete, View. I'm not sure how can I fix that.

Can't really help without knowing exactly how you did the hiding :)

Share this post


Link to post
Share on other sites
2 minutes ago, adrian said:

Can't really help without knowing exactly how you did the hiding :)

Sorry you're right :)

I've edited the function removeTabs:

    public function removeTabs ($tab, $event) {

        $form = $event->return;
        $p = $event->object->getPage();

        if($p->template->name == 'mytemplatename' && $tab == "Children") {
            $fieldset = $form->find("id=ProcessPageEdit".$tab)->first();
        }
        else {
            $fieldset = $form->find("id=ProcessPageEdit".$tab);
        }

        $form->remove($fieldset);
        $event->object->removeTab("ProcessPageEdit".$tab);
    }

 

Share this post


Link to post
Share on other sites

I figured it out. I changed this function:

    public function afterBuildForm(HookEvent $event){

        if($this->user->isSuperuser()) return;

        $form = $event->return;

        foreach($this->data['viewTabs'] as $tab) {
            if(!$this->user->hasPermission("tab-".strtolower($tab)."-view")) {
                $this->removeTabs($tab, $event);
            }
        }

        foreach($this->data['hideTabs'] as $tab) {
            if($this->user->hasPermission("tab-".strtolower($tab)."-hide")) {
                $this->removeTabs($tab, $event);
            }
        }

        $event->return = $form;
    }

to this:

    public function afterBuildForm(HookEvent $event){

        if($this->user->isSuperuser()) return;

        $form = $event->return;
        $p = $event->object->getPage();

        foreach($this->data['viewTabs'] as $tab) {
            if(!$this->user->hasPermission("tab-".strtolower($tab)."-view")) {
                $this->removeTabs($tab, $event);
            }
        }

        foreach($this->data['hideTabs'] as $tab) {
            if($this->user->hasPermission("tab-".strtolower($tab)."-hide") && $p->template->name == 'mytemplatename') {
                $this->removeTabs($tab, $event);
            }
        }

        $event->return = $form;
    }

 

  • Like 1

Share this post


Link to post
Share on other sites

Nice work :)

Or you could try out the new version of the module which adds support in the config settings for restricting by template(s)

Screen Shot 2017-01-31 at 1.15.22 PM.png

  • Like 2

Share this post


Link to post
Share on other sites
5 minutes ago, adrian said:

Nice work :)

Or you could try out the new version of the module which adds support in the config settings for restricting by template(s)

Screen Shot 2017-01-31 at 1.15.22 PM.png

PERFECT :)

Share this post


Link to post
Share on other sites
2 hours ago, adrian said:

Currently no, the module is designed for site-wide use, but you could extend it to have a template selector...

Just wait for about an hour, and @adrian will extend it too :P 

Thank you, BTW!

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Macrura
      Field Descriptions Extended
      This module enables you to extend field descriptions by dividing short descriptions with a longer text that is revealed in a toggle.
      Modules Directory: http://modules.processwire.com/modules/field-descriptions-extended/
      Github: https://github.com/outflux3/FieldDescriptionsExtended
      Extending your field descriptions using the standard field's description field.
      Once this module is installed, it will automatically search your description field for the presence of 5 dashes (-----).
      Any content above the 5 dashes will be visible and the content below the dashes will be hidden. A 'More...' link will appear at the end of the short description which when clicked will reveal the rest of the description.
      Using Simple Markdown Editor with the description field
      If you have Simple Markdown Editor (InputfieldSimpleMDE) installed, you can enable the field description to have that editor.
      *When using Simple MDE, you can use the button (Insert Horizontal Line) instead of typing 5 dashes. More about SimpleMDE.
      Extending your field descriptions using content from a ProcessWire Page for the field description.
      You may use the content from a ProcessWire page as a field description. This would allow you to easily insert images, links, and use hanna codes.
      To use page content for your field descriptions, please follow these instructions:
      Install Select Fields module (FieldtypeFields) http://modules.processwire.com/modules/fieldtype-fields/ Create a new field using this field type, e.g. field_select. Add the field to any template you will be using for your field descriptions. Setup your help pages (for example under a settings branch) where you will store the field description content,using the template containing the Field Select. Add content to a page and select the field where that content should show. To show a short text before the link to the longer content, separate them with 5 dashes Be sure to update your settings on this page, first enable page content descriptions,then specify the name of the Select Fields field, template to search, and content field. If you create a field description using this method, please note that the description field must be blank for contexts where you want the page content to appear.
      You can freely use template context for field descriptions, but the Page Content method is not context sensitive and will display under all contexts where the description is blank.
      ----
      original post:
      This is a new module, hope to release soon, which allows extended field descriptions, in currently 2 ways.
      The main feature of the module is that you can have a short description and then a 'more...' link which drops down a longer block of text.
      This is achieved by separating the intro/visible text and the rest with 5 dashes.

      Example setup:

      the 2nd way is if you are using AdminThemeUiKit, you can show extended field instructions in a panel. The content of the panel is edited on a regular PW page. This use case would probably not be that common, but if you had a field that required some extended instructions for how to use, this could be useful; Also, since this allows you to target information and instructions down at the field level, it could reduce the amount of documentation needed on a global level, since it is a lot more context targeted.

    • By Robin S
      Breadcrumb Dropdowns
      Adds dropdown menus of page edit links to the breadcrumbs in Page Edit.

      Installation
      Install the Breadcrumb Dropdowns module. The module requires ProcessWire >= v3.0.83 and AdminThemeUikit.
      There is a checkbox option in the module config that determines if the breadcrumb dropdowns will include pages that the user does not have permission to edit.
      Features/details
      The module adds an additional breadcrumb item at the end for the currently edited page. That's because I think it's more intuitive for the dropdown under each breadcrumb item to show the item's sibling pages rather than the item's child pages. In the dropdown menus the current page and the current page's parents are highlighted in a crimson colour to make it easier to quickly locate them in case you want to edit the next or previous sibling page. If the option to include uneditable pages is selected then those pages are indicated by a reduced text opacity and the "not-allowed" cursor is shown on hover. There is a limit of 25 sibling pages per dropdown for performance reasons and to avoid the dropdown becoming unwieldy. Incompatibilities
      This module replaces the AdminThemeUikit::renderBreadcrumbs method so will potentially be incompatible with other modules that hook the same method.
       
      https://modules.processwire.com/modules/breadcrumb-dropdowns/
      https://github.com/Toutouwai/BreadcrumbDropdowns
    • By joshuag
      Hey guys, 
      Thought I would share a quick preview of Designme. A module we (Eduardo @elabx and I) are building for visually laying out your templates/edit screens. 🙂
      This is a really quick, zero polish screen grab. FYI. 
      Video #2 - UPDATE
      This new video shows the following features in Designme:
      Re-arranging fields via Drag & Drop Re-sizing fields via Dragging. Adjusting field settings - with live refresh. Working on "hidden" fields while Designme is active. Creating New fields. Deleting fields. Creating/Deleting Tabs. Dragging fields between tabs. Creating fieldsets. Tagging/Un-tagging fields. Fields without headers expand when hovered (like checkboxes). Live filtering of fields in the sidebar. Ability to adjust (all) Template settings without leaving Designme. Template File Tree Editing Template files source code with ACE Editor. Editing Multiple files with ACE Editor. (New Tabs) Saving files. Techie stuff Fields load their own js/css dependancies. *ready to use on creation (*most fields)  Everything happens via Ajax to ProcessPageEdit (via module + hooks). Designme has a JS api that you can use.  All actions trigger events.  We would love any detailed feedback on what you see so far. If you are interested in testing Designme. Let me know below. 🙂
       
       
      Video #1. 
       
    • By dreerr
      TemplateEnginePug (formally TemplateEngineJade)
       
      This module adds Pug templates to the TemplateEngineFactory. It uses https://github.com/pug-php/pug to render templates.
      doctype html html(lang='en') head meta(http-equiv='content-type', content='text/html; charset=utf-8') title= $page->title link(rel='stylesheet', type='text/css', href=$config->urls->templates . 'styles/main.css') body include header.pug h1= $page->title if $page->editable() p: a(href=$page->editURL) Edit Project on GitHub: github.com/dreerr/TemplateEnginePug
      Project in modules directory: modules.processwire.com/modules/template-engine-pug/
       
      For common problems/features/questions about the Factory, use the TemplateEngineFactory thread.
       
    • By tpr
      ProcessNetteTester
      Run Nette Tester tests within ProcessWire admin.
      (continued from here)

      Features
      AJAX interface for running Nette Tester tests, in bulk or manually display counter, error message and execution time in a table run all tests at once or launch single tests show formatted test error messages and report PHP syntax errors stop on first failed test (optional) hide passed tests (optional) display failed/total instead passed/total (optional) re-run failed tests only (optional) auto scroll (optional) include or exclude tests based on query parameters start/stop all tests with the spacebar reset one test or all tests (ctrl+click) https://modules.processwire.com/modules/process-nette-tester/
      https://github.com/rolandtoth/ProcessNetteTester