Builder + curator + multilanguage

has anyone managed to get all this things woks together? i have mixed problem on this, i have a custom plugin and i need some help. Basically the plugin create pages for the frontend pages have blocks with the builder field some block have images, i've implemented curator for this but when i save the page content, i get
Filament\Forms\Components\BaseFileUpload::Filament\Forms\Components\{closure}(): Argument #2 ($value) must be of type array, string given
Filament\Forms\Components\BaseFileUpload::Filament\Forms\Components\{closure}(): Argument #2 ($value) must be of type array, string given
all plugins and filament are latest version
3 Replies
taka92
taka925w ago
I think you should check the File upload field definition -ensure that the value returned from this field is being saved as an array, not a string. -A string might be returned when you are handling the upload incorrectly. You need to ensure the data is being passed correctly as an array and not as a string
awcodes
awcodes5w ago
something like this should help
class CustomCuratorPicker extends CuratorPicker
{
protected function setUp(): void
{
parent::setUp();

$this
->afterStateHydrated(function (CuratorPicker $component, $state) {
if (blank($state)) {
$component->state([]);

return;
}

$state = is_array(Arr::first($state)) ? Arr::first($state)['id'] : $state['id'];
$component->state(get_media_items(Arr::wrap($state)));
})
->dehydrateStateUsing(function ($state) {
if (filled($state)) {
$state = Arr::first($state);

return [
'id' => $state['id'],
'path' => $state['path'],
'alt' => $state['alt'] ?? null,
'width' => $state['width'],
'height' => $state['height'],
];
}

return $state;
});
}
}
class CustomCuratorPicker extends CuratorPicker
{
protected function setUp(): void
{
parent::setUp();

$this
->afterStateHydrated(function (CuratorPicker $component, $state) {
if (blank($state)) {
$component->state([]);

return;
}

$state = is_array(Arr::first($state)) ? Arr::first($state)['id'] : $state['id'];
$component->state(get_media_items(Arr::wrap($state)));
})
->dehydrateStateUsing(function ($state) {
if (filled($state)) {
$state = Arr::first($state);

return [
'id' => $state['id'],
'path' => $state['path'],
'alt' => $state['alt'] ?? null,
'width' => $state['width'],
'height' => $state['height'],
];
}

return $state;
});
}
}
using Curator in a Builder gets tricky, since the builder is storing the id, which can't be referenced directly as a relationship inside a JSON structure. i've come across this myself, just haven't had time to see if there's anything I can do from the plugin to make it work better.

Did you find this page helpful?