Hi @snipi,
well, something very similar to your example to be honest.
Basically I need richtext “Description” and some variable number of properties.
Actually, I was already able to do it with the info you provided. I am just adding complete code here for the seek of documentation:
I extended system_files
table with new columns:
<?php namespace Silence\Galleries\Updates;
use Schema;
use October\Rain\Database\Updates\Migration;
class UpdateSystemModelsFile extends Migration
{
public function up()
{
Schema::table('system_files', function($table)
{
$table->text('properties')->nullable();
$table->text('rich_description')->nullable();
});
}
public function down()
{
Schema::table('system_files', function($table)
{
$table->dropColumn('properties');
$table->dropColumn('rich_description');
});
}
}
After that I basically used your code, just extended it little bit as I needed new property to be jsonable
:
public function boot()
{
File::extend(function($model){
$model->addJsonable('properties');
});
Event::listen('backend.form.extendFields', function($widget) {
if($widget->model instanceof File) {
$widget->removeField('description');
// neccessary condition to avoid duplicating other then repeater fields
if($widget->isNested === false) {
$widget->addFields([
'properties' => [
'label' => 'Properties',
'type' => 'repeater',
'form' => [
'fields' => [
'property' => [
'label' => 'Property',
'type' => 'text',
],
'value' => [
'label' => 'Value',
'type' => 'text'
],
]
]
],
'rich_description' => [
'label' => 'Description',
'type' => 'richeditor'
],
]);
}
}
});
}
There was also small problem with repeater
. By default, when I was creating new item in repeater, it copied also fields outside of the repeater. I had to to add addFields
function inside if($widget->isNested === false
condition in order to avoid this behaviour.
Solution looks like this:
Thank you for your fast help 