We use hook_entity_base_field_info_alter() and hook_entity_bundle_field_info_alter() to alter a entity_reference field's handle, so that we can restrict the selection results.

$fields['field_store']->setSetting('handler', 'custom:group_commerce_store');

But it don't take effect after change field's form widget to select2boxes_autocomplete_multi

These days we give up custom EntityReferenceSelection and use custom Entity Reference views filter instead.
Like this:
qq

When we change to Select2 boxes (Multiple values), Everything works fine ,
But After we enable pre-loaded entries,The Entity Reference views filter lose efficacy

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

caseylau created an issue. See original summary.

lawxen’s picture

Title: Don't work with custom handler » Don't work with custom field handler
matsbla’s picture

Thanks for reporting the issue, please give feedback if you find a way to solve it!

lawxen’s picture

Issue summary: View changes
lawxen’s picture

Status: Active » Needs review
FileSize
4.73 KB

This patch fix all the bugs described in the issue summary no mater which "reference method" we use(custom handler): custom entityRefernce views filter or custom entityRefernceSelection.

lawxen’s picture

Just coding standards optimization and change a comment

-    /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase $selection */
+    /** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $selection */

NO functional change

lawxen’s picture

Issue summary: View changes
FileSize
187.63 KB
73.58 KB
Valentine94’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Thanks, caseylau, patch looks really nice to me

I've applied it and tested locally - everything looks good.

So I don't see any reason to not mark it RTBC and commit asap

  • matsbla committed 880da25 on 8.x-1.x authored by caseylau
    Issue #2980469 by caseylau, Valentine94: Don't work with custom field...
matsbla’s picture

Thanks a lot for that!

matsbla’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.