GB Member Select

The GB Member Select is like an EE Relationships field but instead of listing the channel entries, it lists the members by the selected member roles (or groups for EE5 folks).

Screenshot of GB Member Select on entry edit screen

Installation

Upload the folders to the respective system/user/addons/ and themes/user/ directories and click install on the Add-Ons page.

MySQL 5.6 - users

If you are not running MySQL 5.7 +, please go to system/user/addons/gb_member_select/Helper/ and replace GBMemberSelect.php with GBMemberSelect.php.mysql56. You also need to make sure sort_buffer_size is set to be greater than 256K or higher if you get a Error in query (1038): Out of sort memory, consider increasing server sort buffer size error.

Field Settings

Member Roles/Groups

Select the member roles/groups that you want the field to show members from.

Default Label

The default label representing the member. It is also used for the selector options.

Extra Identifiers

Specify the fields that you want to use when searching the members.

Maximum Members

The usual stuff. You can still search for the members not presented in the list using the filter and search box.

Allow multiple members?

I think it works 😉

Include in search?

Still working on this…

Usage in templates

Parameters

var_prefix

backspace

Variables

{screen_name}

{username}

{email}

{member_id}

{member_custom_field}

{roles} {role:role_id} {role:name} {/roles} (EE6)

{member_groups} {group:group_id} {group:group_title} {/member_groups} (EE5)

Examples

{my_custom_field}
    {if no_results}No related members.{/if}
    {screen_name}
    {username}
    {email}
    {member_id}

    {!-- You can call any member fields by the short_name --}
    {member_custom_field}

    {!-- EE6 --}
    {roles}
        {role:role_id}
        {role:name}
    {/roles}

    {!-- EE5 --}
    {member_groups}
        {group:group_id}
        {group:group_title}
    {/member_groups}
{/my_custom_field}
{my_custom_field var_prefix="my_prefix"}
    {my_prefix:screen_name}
    {my_prefix:username}
    {my_prefix:email}
    {my_prefix:member_id}
    {my_prefix:member_custom_field}

    {!-- EE6 --}
    {my_prefix:roles}
        {role:role_id}
        {role:name}
    {/my_prefix:roles}

    {!-- EE5 --}
    {my_prefix:member_groups}
        {group:group_id}
        {group:group_title}
    {/my_prefix:member_groups}
{/my_custom_field}
{my_custom_field backspace="1"}{member_id},{/my_custom_field}

Note: The {if no_results} condition doesn’t work well in channel entry form tags, I’ll address it in later releases.

Want a selector?

Sure! Here’s how you print a <select> HTML tag:

{exp:channel:entries entry_id="{entry_id}" status="not closed"}
    {exp:gb_member_select:selector
        field_name="my_custom_field"
        name="selector"
        attr:id="my_selector"
        attr:class="form-control select-reporter"
        option_label="screen_name"
        option_value="email"
        selected="{my_custom_field backspace="1"}{member_id},{/my_custom_field}"
        show_empty="yes"
        empty_label="Select a member"}
{/exp:channel:entries}
{exp:gb_member_select:selector
    field_name="my_custom_field"
    name="selector"
    attr:id="my_selector"
    attr:class="form-control select-reporter"
    option_label="screen_name"
    option_value="email"
    selected="{exp:channel:entries entry_id='{entry_id}' status='not closed'}{my_custom_field backspace='1'}{member_id}{/my_custom_field}{/exp:channel:entries}"
    show_empty="yes"
    empty_label="Select a member"
    parse="inward"}

Parameters

field_name (required)

The field short_name.

name

The name="" of your <select>. Default to the field short_name.

selected

Member ids separated by , to be pre-selected.

option_label

What member field to be displayed as the option. Default to the field settings Default Label.

option_value

What member field to be used as the option value. Default to member_id.

Allowed member fields

  • screen_name
  • username
  • email
  • member_id
  • member_custom_field

show_empty

Set to yes if you want the first option to be blank.

empty_label

If show_empty="yes", the text you want to display as the blank option. Default to --.

attr:attribute

You can add HTML attributes like id attr:id="selector", class attr:class="form-select" and data attributeus like attr:data-entry_id="{entry_id}".

Reverse Lookup

GB Member Select lets you lookup the entries you’ve related the members to with any gb_member_select fieldtype by using the {exp:gb_member_select:entries}{/exp:gb_member_select:entries} tag pair.

Parameters

Almost exactly like {exp:channel:entries}{/exp:channel:entries} with 2 more filters:

member_id

The member_id of the member that you want to reverse lookup the entries with. If not specified, the current logged in member will be used to do the reverse lookup.

field_name

The short name of the gb_member_select field that you want to return the related entries from. If not specified, every gb_member_select field will be used to find the entries related to the member.

Examples

Since the gb_member_select entries loop shares exact same variable names with the channel entries loop, please put the gb_member_select entries loop inside an embed if used together. For example, if you have a gb_member_select field called article_by and you’d like to display the related work from this member:

article/item

{exp:channel:entries channel="featured_articles" status="not closed"}
    <h2>{title}</h2>
    <p>{summary}</p>
    <section class="related">
        {embed="_includes/_articles_by" member_id="{article_by}{member_id}{/article_by}"}
    </section>
{/exp:channel:entries}

_includes/_articles_by

{exp:gb_member_select:entries status="not closed" member_id="{embed:member_id}" field_name="article_by"}
    <h3>{title}</h3>
{/exp:gb_member_select:entries}

Caching

To improve performance, GB Member Select caches the field members for each defined GB Member Select field using the EE cache class. If you have a huge list of members (100,000+) that you want to include in a selector, you might need to adjust your PHP memory_limit and max_execution_time to appropriate settings.

There’re also 2 cache status pages in GB Member Select’s add-on settings that you can generate the cache for the fields and entries. If you turn on flush cache settings in the GB Member Select settings page, these cached results will automatically be cleared upon

  • after_member_insert
  • after_member_update
  • after_member_delete
  • member_anonymize
  • after_member_field_update
  • after_member_field_delete

or set to out of sync for the affected fields and channels.

Selected members in entries are also cached, and will automatically get flushed and recreated upon modifications.

Future Goals

  • Grid support
  • Publisher support

Changelog

1.1.0

Added

  • {exp:gb_member_select:entries} to reverse lookup the entries
  • Cache status pages

Updated

  • Enhanced member processing
  • Enhanced caching mechanism

Fixed

  • Frontend bug with the entry_id

1.0.0

  • Hello World!

Support

Email Gilbert at gilbert.lin.web@gmail.com

LinkedIn pictogram Instagram pictogram