Jump to content

Restrict Tab View


adrian

Recommended Posts

  • 1 year later...

Hi @adrian,

Very useful module (as always.) Question though, is there any reason to use Inputfield::collapsedYes rather than collapsedHidden for the _pw_page_name field when removing the settings tab? (Reference line 114 of module code.)   I'd have thought it would be more natural to hide all the fields from the settings tab if the module were setup to hide the Settings tab, not just move the _pw_page_name field into the start of the content tab.

Link to comment
Share on other sites

2 hours ago, netcarver said:

I'd have thought it would be more natural to hide all the fields from the settings tab if the module were setup to hide the Settings tab, not just move the _pw_page_name field into the start of the content tab.

It used to work like that, but it wasn't working for multi-language page names. This change happened in this commit (https://github.com/adrianbj/RestrictTabView/commit/9316082a26315a42d5036481da9d136eb5d4c42e). You could use an older commit, or if you can find a way to make it work while being hidden, I'd love to know. Maybe it needs to be hidden (or positioned off screen) via CSS instead?

  • Like 1
Link to comment
Share on other sites

@adrian

Thanks for the reply. That seems strange - I would have thought the collapsedHidden status would have included it in the form as a hidden input.

For now, I'll just use a hook in my site/ready.php to hide the unneeded tabs as I don't want have any module updates remove changes.

Thanks!

  • Like 1
Link to comment
Share on other sites

9 hours ago, adrian said:

Maybe it needs to be hidden (or positioned off screen) via CSS instead?

Yes, I think the module should do this (or offer an option for it). Because the name field is normally on the Settings tab, and if you are removing that tab for a role then you probably don't want the role seeing any of the fields normally on that tab.

You probably know this but it was new to me... you can add styles to an inputfield without needing to include a CSS file with the module:

$if = $wrapper->getChildByName('_pw_page_name');
$if->wrapAttr('style', 'display:none;');

 

  • Like 4
Link to comment
Share on other sites

Great idea @Robin S - I do know about wrapAttr but I must admit that I often forget about it in situations like this - thanks for the reminder.

I have implemented like this and it seems to be working well now. @netcarver - if you decide to revert to using this module, let me know how it goes for you.

  • Like 2
Link to comment
Share on other sites

What about the Restore tab?

I'm looking at the ProcessPageEdit.module and in ___BuildFormContent() is:

if($this->page->template->nameContentTab) {
    // add InputfieldPageName ...
}

But in ___BuildFormSettings() the condition is different:

if(($this->page->id > 1 || $this->hasLanguagePageNames) && !$this->page->template->nameContentTab) {
    // add InputfieldPageName ...
}

Why?

  • Like 1
Link to comment
Share on other sites

@matjazp - I'll take a look at the new Restore tab - thanks for the reminder.

As for the difference between those two conditions - that's a good question - I am not sure really - you'd think the check for homepage and languagePageNames would be relevant on the content tab as well. I guess maybe because you have to explicitly check the "Display 'name' field in content tab?" option for the home template it's up to you as the dev to decide if you want the name on the Content tab. 

Link to comment
Share on other sites

The "Restore" tab is now supported.

I have also added a new option that lets you display the name field in the Content tab if you have hidden the Settings tab - default is not to show it though.

  • Like 3
Link to comment
Share on other sites

Hi @adrian

I'm seeing an error - apparently due to this module - when trying to add a Repeater item on a page where tabs have been hidden and I'm not logged in as a super-user (all ok when logged in as a Super.)

Fatal error: Uncaught Error: Call to a member function wrapAttr() on null in /site/modules/RestrictTabView/RestrictTabView.module:117 Stack trace:
#0 site/modules/RestrictTabView/RestrictTabView.module(79): RestrictTabView->removeTabs('Settings', Object(ProcessWire\HookEvent))
#1 /wire/core/Wire.php(383): RestrictTabView->afterBuildForm(Object(ProcessWire\HookEvent))
#2 /wire/core/WireHooks.php(825): ProcessWire\Wire->_callMethod('afterBuildForm', Array)
#3 /wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\ProcessPageEdit), 'buildForm', Array)
#4 /wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module(531): ProcessWire\Wire->__call('buildForm', Array)

<snip>

This causes ajax loaded repeater items to fail.

Guarding the call seems to fix it...

                if ($pn instanceof Inputfield) {
                    $pn->wrapAttr('style', 'display:none;');
                }

 

  • Like 1
Link to comment
Share on other sites

@vincent Yes, sounds like the same problem. If you edit the .module file and make the change I posted above, your problem should be resolved.

I cloned the repo and added the change. Can you try my version from here and let me know if that fixes it for you. If so, I'll send a PR over to Adrian.

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

Hi all,

I just added the ability to restrict access to custom FieldsetTabs which makes it easier to block certain user roles from having edit access to entire sets of fields (in the selected tabs).

I also added a new "Exempt Roles" setting that makes it easy to make sure certain roles are not affected by this module - particularly useful if you use the "View" permissions approach.

  • Like 3
Link to comment
Share on other sites

  • 8 months later...

I've been using this for a while with no problems, but have just run into a slight issue. I have a checkbox field 'override' which is in a tab 'system'. The 'system' tab is only allowed for superuser. However, another field in an unrestricted tab uses a visibility condition "override!=1". It seems that, when a non-superuser is logged in, the visibility condition returns false when it should be true, presumably because override cannot be accessed. There are no restrictions on the override field itself.

Any ideas @adrian? I tried a work-round with a hook, assuming that the API would work even if the tab was hidden. The one below is after renderReadyHook, but I also tried a before hook. In each case, the value is applied, but it seems like the form is unchanged.

$this->addHookAfter('Inputfield::renderReadyHook', function(HookEvent $event) {
    $input = $event->arguments(0);
    if ($input and $input->id == 'Inputfield_fieldset_minimal') {
        bd($input, 'input');
        $input->showIf = (wire()->page->overide!=1);
    }
    $event->arguments(0, $input);
    $event->return;
});

 

Edited by MarkE
Additional info
Link to comment
Share on other sites

Hi @MarkE

Sorry I've been so long to respond - way too busy here at the moment.

I don't have a fully working solution for you (I couldn't quite get there as quickly as I need to), but here are some starting points.

The first one is hacky. The second is where you want to end up, but you'll probably want to do a $f->addClass('hidden') or something like that. I also didn't want to use a Markup inputfield but it seemed like there were issues with overriding the main "override" field. Also, using $p->override isn't actually working because it's preventing you from changing the value that is already in the system but if you set it to 0 or 1, you'll see that the approach has merit in that it will change the visibility of your other field. Sorry it's not fully working, but hopefully gets you there. Remember the key thing is that showIf conditions work via JS, so the values need to be available that way, not just via $page->override like you were trying.

$this->addHookAfter('Page::render', function(HookEvent $event) {
    $p = $event->object;
    $event->return = str_replace("</body>", '<input type="hidden" id="Inputfield_override" name="override" value="'.$p->override.'"></body>', $event->return);
});
$this->addHookAfter("ProcessPageEdit::buildForm", function(HookEvent $event) {
    $p = $event->object->getPage();
    bd($p->override);
    $form = $event->return;
    $f = $this->modules->get("InputfieldMarkup");
    $f->attr('id+name', 'override');
    $f->attr('value', '<input type="hidden" id="Inputfield_override" name="override" value="'.$p->override.'">');
    //$f->collapsed = Inputfield::collapsedHidden;
    $form->insertAfter($f, $form->title);

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

 

  • Like 1
Link to comment
Share on other sites

9 hours ago, adrian said:

Sorry I've been so long to respond - way too busy here at the moment.

No worries - thanks for the help

9 hours ago, adrian said:

The first one is hacky

This one works fine ?

9 hours ago, adrian said:

The second is where you want to end up

I suspect I need to mod this a bit to get it working.

Ta muchly!

Link to comment
Share on other sites

11 hours ago, adrian said:

Make sure you limit it to the PageEditor interface in the admin

Sure. In fact, I was wrong to say that it works fine - I needed to make a small adjustment, which also enables more checking. The page object in the hook has the admin template - so we need to get the actual page being edited in order to get the override field. 

$this->addHookAfter('Page::render', function(HookEvent $event) {
    $p = $event->object;
    if ($p->template == 'admin') {
        $pId = wire()->input->get->int('id');
        $page = wire('pages')->get($pId);
        if ($page and $page->template == 'BookingForm') {
            $event->return = str_replace("</body>", '<input type="hidden" id="Inputfield_override" name="override" value="' . $page->override . '"></body>', $event->return);
        }
    }
});

 

  • Like 1
Link to comment
Share on other sites

  • 2 years later...

Hi @adrian,

thank you for providing this helpfull module!

I've found a strange behaviour in my backend: when the "tab-view-hide"-permission is set for a role, the image or file upload fails. Please have a look at my post.

Thank you, best regards
Sebastian

  • 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
×
×
  • Create New...