diff --git a/public/main/inc/lib/extra_field_option.lib.php b/public/main/inc/lib/extra_field_option.lib.php index 7291e90bb06..1f6daec14c5 100644 --- a/public/main/inc/lib/extra_field_option.lib.php +++ b/public/main/inc/lib/extra_field_option.lib.php @@ -383,6 +383,11 @@ public function save_one_item($params, $show_query = false, $insert_repeated = t $order = $this->get_max_order($field_id); $params['option_order'] = $order; } + + if (isset($params['id']) && empty($params['id'])) { + unset($params['id']); + } + if ($insert_repeated) { parent::save($params, $show_query); } else { @@ -611,15 +616,9 @@ public function get_second_select_field_options_by_field($option_value_id, $to_j } /** - * Get options for a specific field as string split by ;. - * - * @param int $field_id - * @param string $ordered_by Extra query bit for reordering - * - * @return string HTML string of options - * @assert (0, '') === null + * Get options for a specific field as string split by ; */ - public function get_field_options_by_field_to_string($field_id, $ordered_by = null) + public function get_field_options_by_field_to_string(int $field_id, string $ordered_by = null): string { $field = new ExtraField($this->type); $field_info = $field->get($field_id); @@ -638,16 +637,20 @@ public function get_field_options_by_field_to_string($field_id, $ordered_by = nu break; default: foreach ($options as $option) { - $elements[] = $option['option_value']; + // If option_value is empty, use display_text + $value = !empty($option['option_value']) ? trim($option['option_value']) : trim($option['display_text']); + if (!empty($value)) { + $elements[] = $value; + } } - $html = implode(';', $elements); + $html = !empty($elements) ? implode(';', $elements) : get_lang("No options available"); break; } return $html; } - return null; + return get_lang("No options available"); } /** diff --git a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php index 2c9b8f0a636..61fd6120168 100644 --- a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php +++ b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php @@ -655,6 +655,7 @@ public function load(ObjectManager $manager): void $extraFieldOption = new ExtraFieldOptions(); $extraFieldOption->setField($extraField) ->setDisplayText($option) + ->setValue($option) ->setOptionOrder(array_search($option, $options) + 1) ;