diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index ef3fdee..4606277 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -247,6 +247,15 @@ public static function currentUser() { } /** + * Gets the uid from the current active user. + * + * @return \Drupal\Core\Session\AccountProxyInterface + */ + public static function getCurrentUserId() { + return static::getContainer()->get('current_user')->id(); + } + + /** * Retrieves the entity manager service. * * @return \Drupal\Core\Entity\EntityManagerInterface diff --git a/core/modules/file/src/Entity/File.php b/core/modules/file/src/Entity/File.php index 8a5bd42..b31b20c 100644 --- a/core/modules/file/src/Entity/File.php +++ b/core/modules/file/src/Entity/File.php @@ -242,6 +242,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The user ID of the file.')) + ->setDefaultValueCallback('Drupal::getCurrentUserId') ->setSetting('target_type', 'user'); $fields['filename'] = BaseFieldDefinition::create('string')