The reference candidates ({shortcode, name}).
Optionalselected: null | stringThe currently-stored shortcode, if any.
Optionalexclude: null | stringA shortcode to omit (e.g. the field owner, to forbid a self-reference).
The options, sorted by label, with any dangling selection appended.
Build the dropdown options for a shortcode-reference field from a list of candidates. Foundry-free so it is unit-testable without a running client.
Candidates with a blank shortcode are skipped and
exclude(a self-reference shortcode) is filtered out; the remainder is sorted by label. Ifselectedis a non-blank shortcode that matches no candidate, a flagged"<code> (unresolved)"option is appended and kept selectable so the stored value is preserved and the dangling reference is visible.