Update BlockAdapter.php
This commit is contained in:
@@ -133,12 +133,12 @@ class BlockAdapter
|
|||||||
];
|
];
|
||||||
|
|
||||||
if ($type === 'select') {
|
if ($type === 'select') {
|
||||||
$setting['options'] = $blockSetting['options'] ?? [];
|
$setting['options'] = $this->normalizeSelectOptions($blockSetting['options'] ?? []);
|
||||||
} elseif ($type === 'yes_no') {
|
} elseif ($type === 'yes_no') {
|
||||||
$setting['type'] = 'select';
|
$setting['type'] = 'select';
|
||||||
$setting['options'] = [
|
$setting['options'] = [
|
||||||
['id' => 0, 'name' => phpb_trans('pagebuilder.no')],
|
['id' => 0, 'label' => phpb_trans('pagebuilder.no')],
|
||||||
['id' => 1, 'name' => phpb_trans('pagebuilder.yes')]
|
['id' => 1, 'label' => phpb_trans('pagebuilder.yes')]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,4 +147,24 @@ class BlockAdapter
|
|||||||
|
|
||||||
return $settings;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user