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

Can't have facet types with the same label (different machine name) as the later group overwrites them #388

Open
andybroomfield opened this issue Aug 23, 2024 · 0 comments

Comments

@andybroomfield
Copy link
Contributor

andybroomfield commented Aug 23, 2024

Sometimes our comms team will have a facet group that is different but has the same visible label as an existing facet type for display. We've noticed that when this happens, it's not actually possible to select facets from this type, or in other cases the previous type. Note this will always be on an exclusive basis, there will never be a directory with both.

I traced the issue to src/Plugin/Field/FieldWidget/FacetFieldWidget.php, though I think this may be a core issue as the options that are being brought back are using the label of the facet type instead of the id, which is causing whichever is later in the list to overwrite them.

$options = $this->getOptions($items->getEntity());

Though also noting

// Trying to imagine the best way round this.
//
// EntityReferenceItem::getSettableOptions() called by ::getOptions()
// removes the bundle from the array if there is only one in the available
// results. At the moment in our case that would be if there is only one
// bundle, or if there are more, but one has accesible values.
//
// I'm lacking imagination at the moment. So this ugly blunt instrument puts
// it back for now.
$raw_options = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($this->fieldDefinition, $items->getEntity())->getReferenceableEntities();
if (count($raw_options) == 1) {
$target_type = $this->fieldDefinition->getSetting('target_type');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo($target_type);
$bundle = key($raw_options);
$bundle_label = (string) $bundles[$bundle]['label'];
$options = [
$bundle_label => $options,
];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant