Update BlockAdapter.php

This commit is contained in:
2026-11-22 12:25:12 +01:00
parent 2aec70849d
commit ef4be66673
@@ -133,12 +133,12 @@ class BlockAdapter
];
if ($type === 'select') {
$setting['options'] = $blockSetting['options'] ?? [];
$setting['options'] = $this->normalizeSelectOptions($blockSetting['options'] ?? []);
} elseif ($type === 'yes_no') {
$setting['type'] = 'select';
$setting['options'] = [
['id' => 0, 'name' => phpb_trans('pagebuilder.no')],
['id' => 1, 'name' => phpb_trans('pagebuilder.yes')]
['id' => 0, 'label' => phpb_trans('pagebuilder.no')],
['id' => 1, 'label' => phpb_trans('pagebuilder.yes')]
];
}
@@ -147,4 +147,24 @@ class BlockAdapter
return $settings;
}
/**
* Normalize select options to use GrapesJS trait format.
* GrapesJS expects options with 'id' (stored value) and 'label' (display text),
* but block configs may use 'id' and 'name'.
*
* @param array $options
* @return array
*/
protected function normalizeSelectOptions($options)
{
$normalized = [];
foreach ($options as $option) {
$normalized[] = [
'id' => $option['id'] ?? $option['value'] ?? '',
'label' => $option['name'] ?? $option['label'] ?? '',
];
}
return $normalized;
}
}