Problem/Motivation
This was raised as a review point in #2784921-135: Add Workspaces experimental module:
+++ b/core/modules/workspace/src/Entity/Workspace.php @@ -0,0 +1,223 @@ + ->setDefaultValueCallback('Drupal\workspace\Entity\Workspace::getCurrentUserId') ... + /** + * Default value callback for 'uid' base field definition. + * + * @see ::baseFieldDefinitions() + * + * @return int[] + * An array containing the ID of the current user. + */ + public static function getCurrentUserId() { + return [\Drupal::currentUser()->id()]; + }
Node and Media also have this, this is the 3th occurance of this exact code + docblock in core, should we open a followup to figure out if it makes sens to move this to a common class, or a trait?
Proposed resolution
Add a EntityOwnerTrait
, similar to EntityPublishedTrait
.
Remaining tasks
Do it.
User interface changes
Nope.
API changes
Nope.
Data model changes
Nope.