I have the following EntityReferenceSelection
plugin:
/**
* Provides an entity reference selection for my_entity.
*
* @EntityReferenceSelection(
* id = "extra:my_entity",
* label = "...",
* entity_types = {
* "my_entity"
* },
* group = "extra",
* weight = 1
* )
*/
class MyEntityExtraSelection extends DefaultSelection {
protected function getAllowedIds() {
return [...];
}
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
$query->condition('id', $this->getAllowedIds(), 'IN');
return $query;
}
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
$allowed = $this->getAllowedIds();
return array_filter($entities, function ($entity) {
return in_array($entity->id(), $allowed);
});
}
}
I'd like to call it extra:my_entity
because I don't want this filtering to occur by default, every time I use it, only when I refer to it using the 'handler' => 'extra'
setting explicitely.
But the core plugin manager gives these errors:
Warning: uasort() expects parameter 1 to be array, null given in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId() (line 65 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).
Warning: end() expects parameter 1 to be array, null given in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId() (line 66 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).
Warning: key() expects parameter 1 to be array, null given in Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager->getPluginId() (line 67 of core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php).