- Issue created by @matslats
- Status changed to Postponed: needs info
8 months ago 4:10pm 3 August 2024 - 🇭🇺Hungary nagy.balint
Hi!
Can you provide more details?
For me at least on 4.0.x if the cardinality is 5 let's say, then I cannot select more than 5 items, the dropdown does not come up.
And it is already using the "max_selected_options" of the chosen library.
var cardinality; if ($element.attr('multiple') && (cardinality = $element.data('cardinality'))) { options.max_selected_options = cardinality; }
Thanks for asking.
My field is actually a basefield, not a field API field. I don't know if that makes a difference.$fields['categories'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Category')) ->setDescription(t('The category or categories of the ad.')) ->setSetting('target_type', 'taxonomy_term') ->setSetting('handler', 'default:taxonomy_term') ->setSetting('handler_settings', ['target_bundles' => ['categories']]) ->setRequired(TRUE) ->setCardinality(3) ->setTranslatable(TRUE) ->setDisplayConfigurable('view', TRUE);
That's all the extra information I can think of right now.
- 🇭🇺Hungary nagy.balint
Maybe in that case it will miss the required attribute and data, which is there on field API fields.
- Status changed to Fixed
5 months ago 11:30am 11 November 2024 On src/ChosenFormRender.php line 73, the #bundle property is required but base fields have no bundle.
if (isset($element['#entity_type']) && isset($element['#bundle']) && isset($element['#field_name'])) {
However, inside that if block, the case of no bundles is handled$field_config = FieldConfig::loadByName($element['#entity_type'], $element['#bundle'], $element['#field_name']); if ($field_config) { $field = $field_config->getFieldStorageDefinition(); } else { \\ cardinality is taken from the basefield definition }
So it looks like a simple bug.
Replace
if (isset($element['#entity_type']) && isset($element['#bundle']) && isset($element['#field_name'])) {
with
if (isset($element['#entity_type']) && isset($element['#field_name'])) {
if (isset($element['#entity_type']) && isset($element['#field_name'])) {
The problem was not because it was a base field but because my entity
- 🇬🇷Greece vensires
It's a really small change and seems to fix the issue correctly. Setting as RTBC.
- 🇭🇺Hungary nagy.balint
The patch seems to be wrong here, since
FieldConfig::loadByName($element['#entity_type'], $element['#bundle'], $element['#field_name']);
still uses bundle, maybe something is missing from the patch.