Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extrafield: Fix field options default value after installation - refs #6138 #6140

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions public/main/inc/lib/extra_field_option.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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");
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/CoreBundle/DataFixtures/ExtraFieldFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;

Expand Down
Loading