Passage Permission and Roles System

Fast, Efficient permissions and roles system for your site pages and resources.

Back to Passage Permission and Roles System Support

chris10207
chris10207

Hi, this plugin rocks ! how would you handle the inGroup for the php side ? i need to use in my own plugin.

Thanks

Last updated

KurtJensen
KurtJensen

Thanks for the question. I have made changes to the plugin today that will make it easier for you to do this. See https://github.com/firemankurt/passage README.md file for all the functions.

To answer your question directly:

// use hasGroup($group_code) to check membership
$isCool = \KurtJensen\Passage\Plugin::hasGroup('cool_people')

Last updated

chris10207
chris10207

Thanks for the updates Kurt, appreciate the speed

however, i m having this exception

[2016-10-05 12:04:38] dev.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined function KurtJensen\Passage\inGroupName()' in /Users/chrisvidal/Sites/smartbuild.asia/site/plugins/kurtjensen/passage/Plugin.php:152
chris10207
chris10207

plugin.php line 152

$answer = inGroupName($group);

should be

$answer = $this->inGroupName($group);

Last updated

chris10207
chris10207

after some testing, i have a different behavior using the new inGroup twig function :

inGroupName('Discovery')

does not behave the same as

inGroup('discovery')

where Discovery is the group name and discovery is the group code

Last updated

KurtJensen
KurtJensen

The PHP method is slightly different from the twig method.

use: hasGroup('discovery') or hasGroupName('Discovery') in PHP written like \KurtJensen\Passage\Plugin::hasGroup('discovery')

use: inGroup('discovery') or inGroupName('Discovery') in twig.

KurtJensen
KurtJensen

chris10207 said:

plugin.php line 152

$answer = inGroupName($group);

should be

$answer = $this->inGroupName($group);

Good catch. I will fix it.

chris10207
chris10207

another qwack here in the private function inGroup() it should be line 150

        $answer = array_key_exists($group, $this->passage_groups());

instead of

        $answer = in_array($group, $this->passage_groups());

in_array will look into the values only, and here we want to look into the keys

Last updated

KurtJensen
KurtJensen

Well that was a dumb mistake! I have made corrections. Please update and try again.

Thank you for point this out. :-)

chris10207
chris10207

a suggestion of new twig function: inGroups() that allow to check if the user is belonging to a set of groups

in plugin.php

 public function registerMarkupTags() {
        return [
            'functions' => [
                'inGroups' => function ($groups) {return $this->inGroups($groups);}
            ],
        ];
    }

then

private function inGroups($lookupGroups){
        return !array_diff((array) $lookupGroups, \KurtJensen\Passage\Plugin::passageGroups());
    }

in your twig file, usage would be

{% if inGroups(['discovery', 'main-account']) %}
{% endif %}

Last updated

KurtJensen
KurtJensen

I know it's been a while but new tags and methods have been added in version 1.0.11

See the updated documentation.

1-11 of 11