Rainlab.User - Extending backend preview form

Why I cannot extend Rainlab.User backend preview form like usual, using:

\RainLab\User\Controllers\Users::extendFormFields(function ($widget) {
    $configFile = plugins_path('namespace/plugin/models/user/fields.yaml');
    $config = Yaml::parse(File::get($configFile));
    $widget->addTabFields(array_get($config, 'fields'));

It works good when updating, but preview uses new/different approach and this solution added no form fields.

+1 here, I could add some custom fields to my user form as usual, but I didn’t find a way to alter the preview form

There’s a new event for this, you tell it what Tab you want to include (“Profile”) then assign a partial for the tab.

Event::listen('rainlab.user.view.extendPreviewTabs', function() {
    return ["Profile" => '$/rainlab/userplus/partials/_user_profile.php'];

Then inside the partial (.../_user_profile.php) you can render the tab, with form fields in it, or anything you like:

<h4 class="my-3 fw-normal"><?= __("Profile") ?></h4>
<?= $this->formRenderPrimaryTab('Profile') ?>

Check out the UserPlus plugin for an example implementation:

1 Like

@daft I see, but was it necessary to break up well known working solution? Or this way will be preferred in future?

Yes, sort of. This is the new way and has better flexibility instead of needing to interact with the form widget just to render some HTML. You can also stack tabs side by side and other fun things.

@daft And combine both approach and automatically generate additive tabs like in update context? :slight_smile: It’s breaking change and preview context is different from update context now (before fixing it manually).

Indeed, it is a breaking change (3.0)