diff -u b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php --- b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php @@ -173,11 +173,16 @@ $bundle_key = $entity_info['entity_keys']['bundle']; $label_key = $entity_info['entity_keys']['label']; - return $entity_manager->getStorageController($target_type)->create(array( + $entity = $entity_manager->getStorageController($target_type)->create(array( $label_key => $label, - $bundle_key => $bundle, - 'uid' => $uid, + $bundle_key => $bundle )); + + if ($entity instanceof EntityAuthorInterface) { + $entity->setAuthorId($uid); + } + + return $entity; } /** only in patch2: unchanged: --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Entity/EntityTest.php @@ -8,6 +8,7 @@ namespace Drupal\entity_test\Entity; use Drupal\Core\Entity\EntityNG; +use Drupal\Core\Entity\EntityAuthorInterface; use Drupal\Core\Entity\Annotation\EntityType; use Drupal\Core\Annotation\Translation; use Drupal\Core\Language\Language; @@ -39,7 +40,7 @@ * menu_base_path = "entity-test/manage/%entity_test" * ) */ -class EntityTest extends EntityNG { +class EntityTest extends EntityNG implements EntityAuthorInterface { /** * The entity ID. @@ -147,4 +148,26 @@ public static function baseFieldDefinitions($entity_type) { ); return $fields; } + + /** + * {@inheritdoc} + */ + public function getAuthor() { + return $this->get('user_id')->entity; + } + + /** + * {@inheritdoc} + */ + public function getAuthorId() { + return $this->get('user_id')->value; + } + + /** + * {@inheritdoc} + */ + public function setAuthorId($uid) { + $this->set('user_id', $uid); + return $this; + } }