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

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

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

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

plugin.php line 152

$answer = inGroupName($group);

should be

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

Last updated

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

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.

chris10207 said:

plugin.php line 152

$answer = inGroupName($group);

should be

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

Good catch. I will fix it.

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

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

Thank you for point this out. :-)

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

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