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
daft
June 26, 2024, 11:21pm
#3
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:
<?php namespace RainLab\UserPlus\Classes;
use Config;
use October\Rain\Extension\Container as ExtensionContainer;
/**
* ExtendUserPlugin
*/
class ExtendUserPlugin
{
/**
* subscribe
*/
public function subscribe($events)
{
$this->extendUserModel();
// User
$events->listen('rainlab.user.view.extendPreviewTabs', [static::class, 'extendPreviewTabs']);
This file has been truncated. show original
1 Like
@daft I see, but was it necessary to break up well known working solution? Or this way will be preferred in future?
daft
June 27, 2024, 7:28am
#5
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? It’s breaking change and preview context is different from update context now (before fixing it manually).
daft
June 27, 2024, 8:37am
#7
Indeed, it is a breaking change (3.0)