diff --git a//core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
index e82ed81..ab45693 100644
--- a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
+++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
@@ -4,6 +4,7 @@ namespace Drupal\Core\Entity\Element;

 use Drupal\Component\Utility\Crypt;
 use Drupal\Component\Utility\Tags;
+use Drupal\Core\Entity\EntityForm;
 use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface;
 use Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface;
@@ -127,6 +128,20 @@ class EntityAutocomplete extends Textfield {
     // Store the selection settings in the key/value store and pass a hashed key
     // in the route parameters.
     $selection_settings = isset($element['#selection_settings']) ? $element['#selection_settings'] : [];
+
+    // Put entity into settings.
+    $form_object = $form_state->getFormObject();
+    if (isset($form_object) && $form_object instanceof EntityForm) {
+      $entity = $form_object->getEntity();
+      if (isset($entity)) {
+        $storage = $form_state->getStorage();
+        if (isset($storage['group'])) {
+          $entity->parent_group = $storage['group'];
+        }
+        $selection_settings['entity'] = $entity;
+      }
+    }
+
     $data = serialize($selection_settings) . $element['#target_type'] . $element['#selection_handler'];
     $selection_settings_key = Crypt::hmacBase64($data, Settings::getHashSalt());

diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
index a559d9e870..37e4e091d1 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
@@ -43,6 +43,25 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter
    * {@inheritdoc}
    */
   public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
+    // Add form object to field definition.
+    $field_definition = $items->getFieldDefinition();
+
+    // Put entity into settings.
+    $form_object = $form_state->getFormObject();
+    if (isset($form_object)) {
+      $entity = $form_object->getEntity();
+      if (isset($entity)) {
+        $storage = $form_state->getStorage();
+        if (isset($storage['group'])) {
+          $entity->parent_group = $storage['group'];
+        }
+
+        $setting = $field_definition->getSetting('handler_settings');
+        $setting['entity'] = $entity;
+        $field_definition->setSetting('handler_settings', $setting);
+      }
+    }
+
     // Prepare some properties for the child methods to build the actual form
     // element.
     $this->required = $element['#required'];
diff --git a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
index 9911f61a0c..bc4715ac4e 100644
--- a/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
+++ b/core/modules/views/src/Plugin/EntityReferenceSelection/ViewsSelection.php
@@ -222,4 +222,45 @@ public static function settingsFormValidate($element, FormStateInterface $form_s
     $form_state->setValueForElement($element, $value);
   }

+  /**
+   * Handles replacing tokens in arguments for views.
+   *
+   * Replaces tokens using Token::replace.
+   *
+   * @param array $args
+   *   An array of arguments that may contain tokens.
+   *
+   * @return array
+   *   The arguments to be sent to the View.
+   */
+  protected function handleArgs($args) {
+    $token_service = \Drupal::token();
+    $options = array(
+      'clear' => TRUE,
+    );
+
+    $data = array();
+    if (isset($this->configuration['handler_settings']['entity'])) {
+      $entity = $this->configuration['handler_settings']['entity'];
+      $entity_type = $entity->getEntityTypeId();
+      if (!isset($data[$entity_type])) {
+        $data[$entity_type] = $entity;
+      }
+    }
+
+    if (isset($this->configuration['entity'])) {
+      $entity = $this->configuration['entity'];
+      $entity_type = $entity->getEntityTypeId();
+      if (!isset($data[$entity_type])) {
+        $data[$entity_type] = $entity;
+      }
+    }
+
+    // Replace tokens for each argument.
+    foreach ($args as $key => $arg) {
+      $args[$key] = $token_service->replace($arg, $data, $options);
+    }
+
+    return $args;
+  }
 }

