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

jp12715
jp12715

Hello I am currently trying to extend the user plugin to allow the user to have an address. I have succeeded in doing this when the user has only one address but I want the user to be able to have multiple.

Im having some issues and cant seem to figure this out. Below is my Plugin.php boot function.

public function boot()
{
    //Extending User Plugin
    UserModel::extend(function($model) {
        $model->hasOne['profile'] = ['Bigmotive\Profile\Models\Profile'];
        $model->hasMany['addresses'] = ['Bigmotive\Profile\Models\Address'];
    });

    UsersController::extendFormFields(function($form, $model, $context){

        if (!$model instanceof UserModel)
            return;

        if (!$model->exists)
                return;

        // Ensures profile model always exists...
        ProfileModel::getFromUser($model);

        $form->addTabFields([
            'profile[phone]' => [
                'label' => 'Phone',
                'tab' => 'Profile',
            ],
             'addresses' => [
                 'label' => 'Address 1',
                 'tab' => 'Address',
                  'type' => '????',
                  'path' => '????'
            ],
        ]);
    });
}

Last updated

Renatio
Renatio

You can use Reapeter field type for this.

http://octobercms.com/docs/backend/forms#widget-repeater

If you want to have Address model than you should use relation widget:

http://octobercms.com/docs/backend/forms#widget-relation

jp12715
jp12715

Got It :D

Last updated

jp12715
jp12715
public function boot()

    {

        //Extending User Plugin

        UserModel::extend(function($model) {

            $model->hasOne['profile'] = ['Bigmotive\Profile\Models\Profile'];

            $model->hasMany['addresses'] = ['Bigmotive\Profile\Models\Address'];

        });

        UsersController::extend(function($controller){

            if(!isset($controller->implement['Backend.Behaviors.RelationController']))

                $controller->implement[] = 'Backend.Behaviors.RelationController';

            $controller->relationConfig  =  '$/bigmotive/profile/controllers/profile/config_relations.yaml';

        });

        UsersController::extendFormFields(function($form, $model, $context){

            if (!$model instanceof UserModel)

                return;

            if (!$model->exists)

                    return;

            // Ensures profile model always exists...

            ProfileModel::getFromUser($model);

            $form->addTabFields([

                'profile[phone]' => [

                    'label' => 'Phone',

                    'tab' => 'Profile',

                ],

                'addresses' => [

                    'label' => 'Address',

                    'tab' => 'Address',

                    'type' => 'partial',

                    'path' => '$/bigmotive/profile/controllers/profile/_addresses.htm',

                    'context' => 'update'

                ]

            ]);

        });

    }

Last updated

1-4 of 4

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