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

De Veste
De Veste

I am trying to extend the User Model with Events. 1 Event is no problem following the great video. But i don not want 1 event but multiple. However when i change it from hasOne to hasMany it errors. (As you can see i am a starter and also from another country so i do not know much about october and i type very poor English!) Still i am looking for some guidance (probably it has something to do with Yaml) cause i am lost Thanks for the help!

raw99
raw99

I think you are not talking about "Events" but about custom profile fields and models. Check this video - https://vimeo.com/123489421

De Veste
De Veste

Yes custom profile called Events which has to hold multiple events. I check all the video's but i am lost cause the way i see it i should edit the yaml file in in the User Model but this according to the video bad practice. Because when this module is updated i loose my changes. So is there a way to make this work? Or should i use a model in between and extend that?

raw99
raw99

you can extend RainLab.User with your own model and add multiple events for that or you can add $hasMany directly to RainLab.User model by extending it, after that you simply need to use "extendFormFields"... Check above video and video about extending RainLab.User plugin.

alxy
alxy

If you need further help, I recommend you post your extend-code (Model::extend(...)) and other relevent files. Which yaml file are you refering to? If you extend the User model you dont work with yaml files, but set the fields directly in PHP code.

De Veste
De Veste

Dear alxy thanks for the help. This is my controller. Before i get comments about you have to fill in the tabs. I know but i want to be able to fill in multiple events so how do i fill in this field so on the backend i get a list of all the events and a add button so i can add them?

<?php namespace Veste\Camping;

use System\Classes\PluginBase;
use Rainlab\User\Models\User as Usermodel;
use Rainlab\User\Controllers\Users as UsersController;
use Veste\Camping\Models\Information as InformationModel;
use Veste\Camping\Models\Events as EventsModel;

/**
 * Camping Plugin Information File
 */
class Plugin extends PluginBase
{

    /**
     * Returns information about this plugin.
     *
     * @return array
     */
    public function pluginDetails()
    {
        return [
            'name'        => 'Camping',
            'description' => 'Camping Informatie en Evenementen',
            'author'      => 'Veste',
            'icon'        => 'icon-leaf'
        ];
    }

    public function boot()
    {
        UserModel::Extend(function($model){
            $model->hasOne['information'] = ['Veste\Camping\Models\Information'];
            $model->hasMany['events'] = ['Veste\Camping\Models\Events'];
        });

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

            if (!$model instanceof UserModel)
                return;

            if (!$model->exists)
                return;

            //Ensure that profile model always exists ...
            InformationModel::getFromUser($model);

            $form->addTabFields([
                'information[title]' => [
                    'label' => 'Title',
                    'tab' => 'Information',
                ],               
                'information[subtitle]' => [
                    'label' => 'Subtitle',
                    'tab' => 'Information',
                ],
                'information[content]' => [
                    'label' => 'Content',
                    'tab' => 'Information',
                    'type' => 'textarea',

                ],
               'information[picture]' => [
                    'label' => 'Picture',
                    'tab' => 'Information',
                    'type' => 'fileupload',
                ]                
            ]);
                        //Ensure that profile model always exists ...
            EventsModel::getFromUser($model);

            $form->addTabFields([
                'events' => [
                  'label' => 'Add Event',
                  'tab' => 'Events',
                  'type' => '????',
                  'path' => '????'
                ]
            ]);
        });
    }
}

Last updated

De Veste
De Veste

someone got a answer?

beaudinngreve10852
beaudinngreve10852

Hey you need to add the the relation fields like so.

    UsersController::extend(function($controller){

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

        $controller->relationConfig  =  '$/veste/camping/controllers/users/config_relation.yaml';
    });
jp12715
jp12715

Was this issue ever solved, im having a similar issue?

1-9 of 9

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