Generate dinamicaly content blocks problem

Hello there, I want to create somehow dinamicaly content blocks on how many languages i have, but the problem is this way, how i try it, it generates same block 4 time per language tab, and i want to generate it just 1 time per each language tab:
No description
No description
No description
3 Replies
Szilárd
SzilárdOP10mo ago
Does anyone know what can generate this problem ? It should be filament problem or i just dont see what i am doing worng on my code no one ?
awcodes
awcodes10mo ago
No one can read you screenshot of the code. Especially with the text highlighted in blue. Try sharing it in a gist or if it’s small enough you can paste it here with proper formatting by enclosing it in 3 backticks. See https://discord.com/channels/883083792112300104/1167015843020943390
Szilárd
SzilárdOP10mo ago
$languages = Language::orderBy('order')->where('status', 1)->get();
$tabs = [];
$lang = [];
foreach ($languages as $key => $language) {
if ($key < $languages->count()) {
if (!array_key_exists($language->id, $lang)) {
$lang = array_merge($lang, [
$language->id]);
\Log::info('Processing language: ' . $language->id);
// Check if blocks for the current language have already been created
if (!isset($languageBlocks[$language->id])) {
// If not, create blocks and store them in the array
$languageBlocks[$language->id] = [
'paragraph' => self::makeParagraphBlock($language),
'button_name' => self::makeButtonBlock($language),
'image' => self::makeImageBlock($language),
'elements_number' => self::makeElementsNumberBlock($language),
];
}

// Use the stored blocks for the current language
$blocks = $languageBlocks[$language->id];

$tabs = array_merge($tabs, [
Forms\Components\Tabs\Tab::make(__($language->name[$language->id]->text))->schema([
Forms\Components\Builder::make('content')
->label('Tartalom')
->collapsible()
->schema($blocks),
])
]);
}
} else {
break;
}

}
$languages = Language::orderBy('order')->where('status', 1)->get();
$tabs = [];
$lang = [];
foreach ($languages as $key => $language) {
if ($key < $languages->count()) {
if (!array_key_exists($language->id, $lang)) {
$lang = array_merge($lang, [
$language->id]);
\Log::info('Processing language: ' . $language->id);
// Check if blocks for the current language have already been created
if (!isset($languageBlocks[$language->id])) {
// If not, create blocks and store them in the array
$languageBlocks[$language->id] = [
'paragraph' => self::makeParagraphBlock($language),
'button_name' => self::makeButtonBlock($language),
'image' => self::makeImageBlock($language),
'elements_number' => self::makeElementsNumberBlock($language),
];
}

// Use the stored blocks for the current language
$blocks = $languageBlocks[$language->id];

$tabs = array_merge($tabs, [
Forms\Components\Tabs\Tab::make(__($language->name[$language->id]->text))->schema([
Forms\Components\Builder::make('content')
->label('Tartalom')
->collapsible()
->schema($blocks),
])
]);
}
} else {
break;
}

}
return $form->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\TextInput::make('id')->hidden(),
Forms\Components\Card::make()
->schema([
Forms\Components\TextInput::make('content_blocks')->label('Blok név'),
]),
Forms\Components\Tabs::make('Localization')->tabs($tabs),
]),
]);˛
return $form->schema([
Forms\Components\Card::make()
->schema([
Forms\Components\TextInput::make('id')->hidden(),
Forms\Components\Card::make()
->schema([
Forms\Components\TextInput::make('content_blocks')->label('Blok név'),
]),
Forms\Components\Tabs::make('Localization')->tabs($tabs),
]),
]);˛
so this is my public static function form(Form $form)
private static function makeParagraphBlock($language)
{
return Forms\Components\Builder\Block::make("paragraph")
->id(Str::uuid())
->label('Bekezdés')
->schema([
Forms\Components\RichEditor::make('content.' . $language->id)->label('Bekezdés'),
]);
}
private static function makeParagraphBlock($language)
{
return Forms\Components\Builder\Block::make("paragraph")
->id(Str::uuid())
->label('Bekezdés')
->schema([
Forms\Components\RichEditor::make('content.' . $language->id)->label('Bekezdés'),
]);
}
makeSomething functions look like that :/
Want results from more Discord servers?
Add your server