diff --git a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php
index 5e9b2cd3c6..e6119195ae 100644
--- a/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php
+++ b/core/lib/Drupal/Core/Entity/EntityReferenceSelection/SelectionPluginManager.php
@@ -60,11 +60,12 @@ public function getInstance(array $options) {
    */
   public function getPluginId($target_type, $base_plugin_id) {
     // Get all available selection plugins for this entity type.
-    $selection_handler_groups = $this->getSelectionGroups($target_type);
+    $plugin_handler_groups = $this->getSelectionGroups($target_type)[$base_plugin_id] ?? [];
 
     // Sort the selection plugins by weight and select the best match.
-    uasort($selection_handler_groups[$base_plugin_id], ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
-    $plugin_id = array_key_last($selection_handler_groups[$base_plugin_id]);
+    uasort($plugin_handler_groups, ['Drupal\Component\Utility\SortArray', 'sortByWeightElement']);
+
+    $plugin_id = array_key_last($plugin_handler_groups);
 
     return $plugin_id;
   }
