Skip to content
Field type for Craft CMS that let you select one or more user groups
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
resources
src
.craftplugin
.gitignore
CHANGELOG.md
LICENSE.md
README.md
composer.json
icon.sketch

README.md

User Group Field plugin for Craft CMS 3.x

Field type that let you select one or more user groups

Icon

Screenshot

Screenshot

Requirements

This plugin requires Craft CMS 3.0.0 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require superbigco/craft-usergroupfield
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for User Group Field.

User Group Field Overview

This plugin provides an Field Type where you can select one or more user groups.

Configuring User Group Field

There is 3 display modes:

  • As a dropdown, where you can select only 1 group
  • As a group of checkboxes, where you can select 1 or more groups
  • As a group of radio buttons, where you can select only 1 group

Using User Group Field

To list the group(s) selected:

{% set groups = entry.userGroupFieldHandle.getGroups() %}
{% for group in groups %}
    {{ group.name }}
{% endfor %}

To get only the first group

{% set groups = entry.userGroupFieldHandle.getGroups()|first %}
{{ group.name }}

To check if the current user is in any of the groups selected

{% if entry.userGroupFieldHandle.inGroup(currentUser) %}
    <h1>User can access</h1>
{% endif %}

To check if the current user can access something based on the group selection

{% if entry.userGroupFieldHandle.canAccess(currentUser) %}
    <h1>User can access</h1>
{% endif %}

Note: This check is always true for admins.

Brought to you by Superbig

You can’t perform that action at this time.