2

I'd like to be able to select a user for a settings field for my plugin.

Is there a settings AttributeType that matches users? And a corresponding forms template for picking a user?

(also interesting would be picking assets/elements from a certain section)

2

Copying from the widgets settings I made something that sort of works:

Define the setting to be type mixed:

protected function defineSettings()
{
    return array(
                 'jobsemail' => array(AttributeType::Mixed, 'required'=>false),
                 );
}

Then create a settings.html like this:

{% import "_includes/forms" as forms %}

{% set userInput %}
    <div class="select">
        <select id="jobsemail" name="jobsemail">
          <option value="">No one</option>
            {% for user in craft.users.group('Admin') %}
          <option value="{{ user.id }}"{% if user.id == settings.jobsemail %} selected{% endif %}>{{ user.name|t }}</option>
            {% endfor %}
        </select>
    </div>
{% endset %}

{{ forms.field({
    label: "Email recipient"|t,
    instructions: "This person gets emailed when new jobs are added"|t,
    id: 'jobsemail',
}, userInput) }}

This gives you a basic SELECT drop-down list. It's ok here, because the number of admin users is low. It would be less suitable if there were 100s of users.

Is a better solution with a real pop-up element picker would be nice!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.