Math_syo
Math_syo
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
I understand that it could be another solution but I prefer the way I'm trying to do. If there is absolutely no solution I'll try yours, thanks ^^
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
In english the "image" field is a curator relationship, so in french I should only have the curator media ID, as in english, not all his attributes... ^^'
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
Moreover, the saved version of french or english seams to don't be whats expected :
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
I can save a french and english for my builder but after saved, if I switch from french to english I have this error. It seams to be a known issue but is there a solution ?
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
My issue/the error:
count(): Argument #1 ($value) must be of type Countable|array, int given
count(): Argument #1 ($value) must be of type Countable|array, int given
18 replies
FFilament
Created by Math_syo on 4/9/2024 in #❓┊help
Translatable Builder/Repeater Form Field
What I am trying to do: Translate a builder form field Code: My Page model :
class Page extends Model
{
use HasFactory, HasTranslations;

protected $table = "filament_fabricator__pages";
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'name',
'title',
'blocks',
];

/**
* The attributes that should be translatable.
*/
public $translatable = [
'title',
'blocks',
];

protected $casts = [
'blocks' => 'array',
];
}
class Page extends Model
{
use HasFactory, HasTranslations;

protected $table = "filament_fabricator__pages";
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'name',
'title',
'blocks',
];

/**
* The attributes that should be translatable.
*/
public $translatable = [
'title',
'blocks',
];

protected $casts = [
'blocks' => 'array',
];
}
My Filament Ressource :
public static function form(Form $form): Form
{
return $form->schema([
Forms\Components\Grid::make(1)->schema([
Forms\Components\Section::make()->schema([
Forms\Components\TextInput::make('title')
->required(),

Forms\Components\TextInput::make('name')
->label(__('Name'))
->required(),
]),
]),

Forms\Components\Grid::make(1)->schema([
Builder::make('blocks')
->label(__('filament-fabricator::page-resource.labels.blocks'))
->blocks(FilamentFabricator::getPageBlocks())
->mutateDehydratedStateUsing(static function (?array $state): array {
if (! is_array($state)) {
return array_values([]);
}

$registerPageBlockNames = array_keys(FilamentFabricator::getPageBlocksRaw());

return collect($state)
->filter(fn (array $block) => in_array($block['type'], $registerPageBlockNames, true))
->values()
->toArray();
}),
]),
]);
}
public static function form(Form $form): Form
{
return $form->schema([
Forms\Components\Grid::make(1)->schema([
Forms\Components\Section::make()->schema([
Forms\Components\TextInput::make('title')
->required(),

Forms\Components\TextInput::make('name')
->label(__('Name'))
->required(),
]),
]),

Forms\Components\Grid::make(1)->schema([
Builder::make('blocks')
->label(__('filament-fabricator::page-resource.labels.blocks'))
->blocks(FilamentFabricator::getPageBlocks())
->mutateDehydratedStateUsing(static function (?array $state): array {
if (! is_array($state)) {
return array_values([]);
}

$registerPageBlockNames = array_keys(FilamentFabricator::getPageBlocksRaw());

return collect($state)
->filter(fn (array $block) => in_array($block['type'], $registerPageBlockNames, true))
->values()
->toArray();
}),
]),
]);
}
18 replies