This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

wilirius15434
wilirius15434

So there's the screencast that shows you how to edit the Users plugin, and I followed it roughly to extend the Backend Users, but the forms are not showing up.

wilirius15434
wilirius15434

The tables were added to the database as foreign keys.

Code:

use System\Classes\PluginBase;
use Backend\Models\User as BackendUserModel;
use Backend\Controllers\Users as BackendUsersController;

class Plugin extends PluginBase
{
    public $require = ['Backend.Models.User'];

    public function boot()
    {
        // Add college and teacher field to Users table
        BackendUserModel::extend(function($model){
            $model->belongsTo['teacher'] = ['Ex\Vct\Models\Teacher'];
            $model->belongsTo['college'] = ['Ex\Vct\Models\College'];
        });

        // Add college and teacher field to Users form
        BackendUsersController::extendFormFields(function($form, $model, $context){

            if (!$model instanceof BackendUsersController)
                return;

            $form->addTabFields([
                'teacher' => [
                    'label'   => 'Teacher',
                    'comment' => 'Associate this user with a teacher.',
                    'type' => 'recordfinder',
                    'list' => '$/ex/vct/models/teacher/columns.yaml',
                    'prompt' => 'Click the %s to find a teacher',
                    'select' => 'concat(first_name, " ", last_name)',
                    'tab' => 'account'
                ],
                'college' => [
                    'label'   => 'College',
                    'comment' => 'Associate this user with a college.',
                    'type' => 'recordfinder',
                    'list' => '$/ex/vct/models/college/columns.yaml',
                    'prompt' => 'Click the %s to find a college',
                    'nameFrom' => 'name',
                    'tab' => 'account'
                ],
            ]);
        });
    }

Last updated

wilirius15434
wilirius15434

Found it - was checking for the controller but should have been checking for the model.

        ...
        // Add college and teacher field to Users form
        BackendUsersController::extendFormFields(function($form, $model, $context){

            if (!$model instanceof BackendUserModel)
                return;
        ...

Last updated

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.