Show all elements even with the same label value

Created on 12 April 2022, over 2 years ago
Updated 11 November 2023, about 1 year ago

Problem/Motivation

When a list of reference elements is shown in the drag & drop widget and more than one has the same label value. At first, we can see all of them in the available list (left side) but if we move one of them (elements with the same label) to the selected list (right side) and save it. When we try to edit we can't see the elements with the same label in the available list.

Steps to reproduce

- create a taxonomy vocabulary with terms with the same title (label) value.
- create a taxonomy term (entity reference) in a content with the drag & drop widget.
- move one of the repeat terms from the available entities (left side) to the selected entities (right side).
- save.
- Edit again this content (just one of the repeat terms appears in the selected entities but the others disappear).

Proposed resolution

Modify the getAvailableOptions method to filter the elements using the id and not the label

  protected function getAvailableOptions(FieldItemListInterface $items) {
    // We need to check against a flat list of options.
    $flat_options = OptGroup::flattenOptions($this->getOptions($items->getEntity()));
    $selected_options = $this->getSelectedOptions($items);

    $available_options = [];
    foreach ($flat_options as $id => $option) {
      if (!array_key_exists($id, $selected_options)) {
        $available_options[$id] = $option;
      }
    }

    return $available_options;
  }
🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇴Colombia mauricio.galindo

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024