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

Utility
Utility

The User plugin is convenient to use. However, we want to extend it by adding more user attributes, e.g., age, gender. We would like to write our own plugin to extend Rainlab.User. How could we do that?

The doc mentions that we can extend the User model in Plugin.php/root() by adding a new relation. But what about attributes? And the form on the view?

Last updated

johnsvensson19424
johnsvensson19424

I would also like to know more, for instance If I would want to enhance the Forums plugin with signatures in the bottom of a post, what would be the best way to accomplish this?

daftspunky
daftspunky

Hi,

Use the backend.form.extendFields event to extend the existing forms. The plugin's boot() method allows to register listeners and extend models. Example (from the Forum plugin):

public function boot()
{
    User::extend(function($model) {
        $model->hasOne['forum_member'] = ['RainLab\Forum\Models\Member'];
    });

    Event::listen('backend.form.extendFields', function($widget) {
        if (!$widget->getController() instanceof \RainLab\User\Controllers\Users) return;
        if ($widget->getContext() != 'update') return;
        if (!Member::getFromUser($widget->model)) return;

        $widget->addFields([
            'forum_member[username]' => [
                'label' => 'Username',
                'tab' => 'Forum',
                'comment' => 'The display to represent this user on the forum.',
            ],
            'forum_member[is_moderator]' => [
                'label' => 'Forum moderator',
                'type' => 'checkbox',
                'tab' => 'Forum',
                'span' => 'auto',
                'comment' => 'Place a tick in this box if this user can moderate the entire forum.',
            ],
            'forum_member[is_banned]' => [
                'label' => 'Banned from forum',
                'type' => 'checkbox',
                'tab' => 'Forum',
                'span' => 'auto',
                'comment' => 'Place a tick in this box if this user is banned from posting to the forum.',
            ],
        ], 'primary');
    });
}
Utility
Utility

Does this mean I have to store all extended attributes in another table? I managed to add columns to the users table using scripts in the updates folder of my own plugin. But how can I update $fillable of User model in boot()?

Utility
Utility

It seems that there is no need to update $fillable of the RainLab.User model. Things work fine. Great!

Utility
Utility

Well, stuck again ... How can I add visible columns while listing all users?

cpass78
cpass78

Would also like more info on this as well. How should one override a view? Im looking to add more classes for my themes without having to modify the core plugins css.

jekinney
jekinney

To update your DB tables you can add to the migration file as necessary and force an update which will update the tables as required. In the model class will automatically have the column names available for use. This goes with the last question by cpass78 also, you don't have to use the default views by using the {% component 'forum' %} instead use something like: [forumChannels] memberPage = "account" channelPage = "404" topicPage = "404" {{ forumChannel.title }}

The forumChannel will expose all table column names from your data base to use with the prefix forumChannel.(colum name).

Then you can use your own html and/or css

Last updated

Utility
Utility

Hi jekinney, does this mean just write own pages/partials, rather than using the component from the plugin?

cpass78
cpass78

Forgive my density but could you clarify a bit on the above jekinney? Say I want to override the user component views because my bootstrap theme signup/register pages use different css classes from the defaults included.

The values you state above, they would go in the config area of the page, above the == correct?

Thank you

a2thek26
a2thek26

So what exactly is the process for overriding a view for a component? Is there a component parameter to define a path for an alternative view? Or is there a default path structure in the theme that should be used to define view overrides?

Searched through the docs but can't seem to find anything.

Last updated

TheOneWhoDid
TheOneWhoDid

I too would like to know more about this.

I'm rather lay when it comes to this more complicated stuff, so perhaps a simple demo or a tutorial should be put in place for people like me?

Shahiem
Shahiem

Is it possible to extend an existing navigation?

Blackpig Creative
Blackpig Creative

I'm also wanting override a view. I found the following on the RainLab.Blog plugin page:

The post list and the pagination are coded in the default component partial plugins/rainlab/blog/components/posts/default.htm. If the default markup is not suitable for your website, feel free to copy it from the default partial and replace the {% component %} call in the example above with the partial contents.

Which I think means instead of using {% component 'blogPosts' %}, you should place your amended code block instead:

<ul class="post-list">
    {% for post in posts %}
        <li>
            <h3><a href="{{ postPage|page({ (postPageIdParam): post.slug}) }}">{{ post.title }}</a></h3>
etc...

This is a bit of a shame really - I don't want to be messing with source of the plug-in or copyimg my amended version of the code across several different pages - and thus have to maintain it across different pages. Ideally we should be able to override plug-in views/partials - either via a passed param or as a default behaviour: October searches through the active theme/theme_name/plugins/path/to/component/view.htm e.g. theme/my_theme/plugins/blog/components/posts/default.htm

Last updated

milos.stanic
milos.stanic

I think the partials can be overridden. Please take a look at https://github.com/octobercms/docs/issues/18 It says that in your theme dir you should create a partial file with identical name with the one you want to override, and voila.

JonasJonny
JonasJonny

Thank you @milos, that is exactly what I was looking for. I read it earlier but I didn't find the link to this document again.

All component partials can be overridden using the theme partials. Following from the previous example, if our component called channel uses the title.htm partial. We can override the partial by creating a file in our theme called partials/channel/title.htm.

The file path is broken down like this:

partials - the theme partials directory
channel - the component alias (a partial subdirectory)
title.htm - the component partial to override
ericbangug9182
ericbangug9182

How do you extend the plugin only to modify the form field type from fields.yaml?

benm
benm

ericbangug9182 said:

How do you extend the plugin only to modify the form field type from fields.yaml?

I've been also trying to change a form field type by extending the Rainlab Blog extension. No luck so far.

Jaap
Jaap

If i understand you correctly you can just modify the plugin.php boot() function and insert BlogController::extendFormFields(function($form, $model, $context){ $form->removeField('field1') $form->addFields([ 'field1' => [ 'label' => 'fieldlabel', 'type' => 'Newtype', ]

benm
benm

Thanks. It's been a while since I was trying to solve this. I long since figured out a solution a little messier but along the same lines. Also got some similar feedback on Stack Overflow. will let you know if I end up trying this if it works.

Last updated

1-20 of 22

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