Problem/Motivation
Unless a user already exists in a site import, which precludes the use case of installing content into an empty database, the UID is unknown at the time of content definition. Support needs to be added to reference users for author assignment using identifiers known or assignable at the time of defining content in the import files.
Proposed resolution
Add an event subscriber to process Node imports and assign authors with additional processing to expand support of identifiers to the following:
- UID
- UUID
- User Name
API changes
Nodes in import content may be assigned authors by defining a UID, UUID, or user name in the Node's uid
attribute using the following format:
- entity: node
type: article
uid: <user_id>|<uuid>|<username>
Comment | File | Size | Author |
---|---|---|---|
#8 | interdiff-2876203-7-8.txt | 5.89 KB | marvil07 |
#8 | 2876203-8.patch | 6.5 KB | marvil07 |
#7 | support_load_user-2876203-7.patch | 6.37 KB | marvil07 |
#5 | support_load_user-2876203-5.patch | 6.42 KB | slucero |
Comments
Comment #2
sluceroChanging this to target v1.x since that's the currently supported version.
Comment #3
sluceroCurrently this cannot be achieved since processing within the entity is only triggered at the field level after properties have been assigned. These properties are filtered out within the
ContentLoader::buildEntity()
method where each content key starting withfield
is filtered out.This feature could be implemented through a couple of methods:
Option A: Special UID Handling
During the entity build process, the
uid
property is specifically checked for whether it contains a string or a numeric value. If it contains a string value we assume it's the username and use that to lookup and replace the UID value.Option B: Extend Processing Support to Properties
Rather than only checking content keys matching
field*
for preprocessing, this could be extended to all properties. This adds some complexity in the preprocessing options since most properties have to be assigned a raw value instead of an array containing avalue
ortarget_id
like other field values, but the added flexibility could be valuable since not all fields are guaranteed to follow thefield_*
naming scheme if they weren't created through the Field UI.Moving Forward
Overall, Option A is definitely the quicker route to this functionality, and it accounts for a common enough use case to likely make it worthwhile. Option B, however, offers more flexibility to the processing logic that should probably be added in at some point in the future either way.
Comment #4
bjlewis2 CreditAttribution: bjlewis2 commentedFollowing this because I was just trying to figure out how to do this.
My use case:
I'm creating a group using the "group" module (which works fine), but with that module, the creator has the "Admin" role within the group. So, since it's created by "Anonymous", as user1 I don't have access/permission in the group. I can join the group, and make it work that way, but that adds manual steps to an otherwise automated process.
My 2 cents:
I'd like to see Option A implemented personally (since it covers the basic use-case, and sounds like it'd be quicker/simpler). Maybe Option B would be a part of the 2.x version of the module.
Thanks again for the great module!
Comment #5
sluceroIn the attached patch I've added a new event subscriber to process the
uid
property of Nodes being imported if the user is not successfully, such as in the case that a numeric user Id is not provided. This event subscriber then adds processing to identity a user for assignment as the Node's author by first checking if a valid UUID was provided and then searching for the user name if not.Comment #6
sluceroWork in this is directly related to and could benefit from the refactoring proposed in #2949625: Move Entity Loading and Lookup into Helper Service.
Comment #7
marvil07 CreditAttribution: marvil07 at Adapt commentedQuite useful extension, thanks!
It is not applying anymore, here a re-roll for current 8.x-1.x, at 8.x-1.0-alpha9.
Comment #8
marvil07 CreditAttribution: marvil07 at Adapt commentedHere an alternative patch, generalizing to apply it not only to Node entities, but any EntityOwnerInterface.
This is useful on entities like profile module entities, that are not nodes but have ownership.
Additionally, an interdiff, via git for easier read on the rename.