Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi, thank you for the great work.
i dont know if this a bug or a feature request, but when i try the import mapping of users , Roles should be listed in select target drop down list and may be the langcode too for all entities that is supposed to be imported.
Thanks in advance for the great work i've been waiting for a long time for this mod. to port to D8.
Comment | File | Size | Author |
---|---|---|---|
#28 | interdiff-2933361-27-28.txt | 4.9 KB | MegaChriz |
#28 | feeds-config-entityreference-2933361-28.patch | 70.84 KB | MegaChriz |
| |||
#14 | select a target.png | 1.23 MB | lomale@bluewin.ch |
#8 | demo-user-with-role-field-imported-succesfully.png | 15 KB | vijay.mayilsamy |
#8 | demo-user-csv.png | 15.48 KB | vijay.mayilsamy |
Comments
Comment #2
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedAgreed. A role mapping target hasn't been implemented yet for the D8 version. Patches are welcome.
For reference, this was the equivalent issue for D7: #1376774: User Processor - add mapping target for user roles. Could be used to get ideas for how the role target should be implemented.
Comment #3
yassine makke CreditAttribution: yassine makke commentedHi thank you for the reply, i ended up using migration csv import which worked but after learning and searching a bit.
But with Feeds UI it could be a lot better and easier "i think".
thanks any way.
Comment #4
saranya ashokkumar CreditAttribution: saranya ashokkumar at UniMity Solutions Pvt Limited commentedI am also looking for the role mapping. I created new feeds target as checkbox. But It is not showing in the mapping place.
Am I missed anything? Can anyone guide me what I have to do? My code is:
Comment #5
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedI think that "checkboxes" is not the field type of the roles field. "checkboxes" say something about how you input the roles field in the UI, thus the field widget. If you look at
\Drupal\user\Entity\User::baseFieldDefinitions()
you see that "roles" is an entity reference field:A role entity is a configuration entity. Currently, Feeds only has support for entity reference fields that references content entities.
Luckily, I have been working on support for referencing config entities as well. Attached is a patch for that. I have not tested if it works for roles: I needed this Feeds target for an other entity reference field.
Comment #6
saranya ashokkumar CreditAttribution: saranya ashokkumar at UniMity Solutions Pvt Limited commentedHi MegaChriz,
It's working fine! Thank you so much.
Comment #7
kclarkson CreditAttribution: kclarkson as a volunteer and at Drupal Diversity & Inclusion commentedI have applied the patch to 8.x-3.x and was able to import user roles from a CSV.
User Role Feeds Notes:
Comment #8
vijay.mayilsamy CreditAttribution: vijay.mayilsamy commentedHi All,
I have applied the patch and roles field appear in the target after applying the patch.
Tested by importing the users to the system with roles column added to the demo content.
Herewith i'm attaching the following files:
Changing the status to RTBC
Thanks
Vijay
Comment #9
jamesdixon CreditAttribution: jamesdixon as a volunteer and at Dialed In Design commentedThanks @vijay.mayilsamy! Code looks good to me from #5. Do we care there were a couple of failures in older versions of PHP?
Comment #10
jamesdixon CreditAttribution: jamesdixon as a volunteer and at Dialed In Design commentedWith PHP5 end of life at the end of 2018 not sure fixing those 2 failed tests is a priority.
Comment #11
MegaChriz CreditAttribution: MegaChriz as a volunteer commented@jamesdixon
I think that test is a random test failure as it fails on:
I think there are two things left to do here:
Comment #12
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedHere's an updated patch with tests. Note that this patch doesn't only allow you to map to roles, but also to any other entity reference field that targets a config entity. New in this patch also is the possibility to reference by properties other than ID on the config entity. The data type of these properties need to be a string or an integer.
About the revoke roles issue: I think it's bad UX having other roles be revoked. Thus status remains "Needs work".
Comment #13
rcodina CreditAttribution: rcodina commentedPatch on #12 works for me. I have used it to map user roles. Many thanks @MegaChriz!
Comment #14
lomale@bluewin.ch CreditAttribution: lomale@bluewin.ch as a volunteer and commentedHi
I'm coming back on this issue.
I used feeds an imported the users. but one thing didn't work. I wasn't able to map to roles.
does it mean that there is a patch, but the patch is not integrated in the current release.
I use Drupal 8.8.1 and feeds 8.x-3.0-alpha6
I added the pictures
select a target
what can I do. I not used to patch though I could run Drush. how would I have to patch #12
thanks for help Lothar
Comment #15
lomale@bluewin.ch CreditAttribution: lomale@bluewin.ch as a volunteer and commentedComment #16
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedAdding this as a beta blocker.
Comment #17
lomale@bluewin.ch CreditAttribution: lomale@bluewin.ch as a volunteer and commentedSorry can you tell me what you mean by this. "Adding this as a beta blocker".
I would appreciate if you write down the sentence I have to use to add the patch to my testsite.
feeds-config-entityreference-2933361-12.patch
site/drupal_test
I would like to test that if it is useful and works for me.
Thanks
Comment #18
rcodina CreditAttribution: rcodina commented@lomale Copy the patch file inside the module directory. Better if you use the latest dev version. Then do this:
patch -p1 < feeds-config-entityreference-2933361-12.patch
Please, give feedback about the patch.
Comment #19
boabjohn CreditAttribution: boabjohn commented#12 works for me...thanks heaps!!
Comment #20
rcodina CreditAttribution: rcodina commentedComment #21
kierduros CreditAttribution: kierduros commentedIt looks like the refactoring that went on for Alpha7 removed what the most recent patch in this thread was modifying to make user roles an importable aspect of the user record.Any timeframe for when there'll be a new patch or when the functionality will get incorporated into a release? (I'd offer to help, but, well... if I could do it, I wouldn't be asking... I'd be posting a patch.)
(Or maybe my copy just isn't patching correctly at all... which wouldn't be unheard of with all the problems I've been having lately in my dev environment... ~sigh~)
Yep. Just my dev environment acting up.
When the patch is properly applied, it works great. Thanks.
Comment #22
MegaChriz CreditAttribution: MegaChriz as a volunteer commented@kierduros
We are aiming to get this issue finalized by October 1 this year. The Feeds team is currently focussed on other issues and when some of these are done, this one will be the next in line.
Here’s a brief schema of what we’re working on right now:
https://docs.google.com/spreadsheets/d/1cn4vmHosTfxgyI0zlvVv_ce94715eH-m...
If you’re able to help out - especially on the Tamper issues - the chances that this issue actually gets done before October 1 will go up.
This issue could also use an issue summary update. What’s left to be done is noted in comment #11 and #12.
Comment #23
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedRegarding the user role target, this ports the following from the D7 version of Feeds:
There's now a separate target for user roles and a more generic one for other config entity references.
Maybe needs an unit test for the new UserRole target.
Comment #24
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedReroll (needed after committing #2989279: Add a target to entity ID).
Also coding standard fixes.
Comment #25
nevergone CreditAttribution: nevergone commentedTested and works well!
Comment #26
Taiger CreditAttribution: Taiger commented#24 worked for me.
I am on
Drupal core 8.9.11
Feeds 8.x-3.0-alpha9
This is an essential feature! Thank you!!
Comment #27
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThis patch adds unit tests for FeedsTarget plugins "ConfigEntityReference" and "UserRole".
It also changes/fixes the following:
Comment #28
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedThis patches fixes coding style and also changes the error message for when a role could not be found.
The message was:
And now is:
I think this is ready (if tests still pass). I plan to commit it in a few days.
Comment #30
MegaChriz CreditAttribution: MegaChriz as a volunteer commentedCommitted #28. Only one beta blocker to go!
Thank you all for testing.
Comment #32
superlolo95 CreditAttribution: superlolo95 commentedHello,
Could you clarify me why there are 2 mappers for the entity_reference type?
For my custom module to work, I had to modifiy this mapper in order it be not used by my custom module (for entity_reference fields).
Thanks
Comment #33
MegaChriz CreditAttribution: MegaChriz as a volunteer commented@superlolo95
There are actually three entity reference mappers:
For config and content entity reference fields, there are different targets, because there are differences on how to handle the targets. For content entity reference fields, there's a setting to use a field to reference an entity by. Config entities don't have fields, so that target provides you options to select an entity by certain properties of the config entity instead.
Then there's the UserRole target, which extends ConfigEntityReference. The UserRole target has some extra configuration options. You can configure which roles Feeds should accept, if non-existing roles should be autocreated and if Feeds should also revoke existing roles on the user if the source doesn't provide them.
What issue did you experience with your custom module and which of the three entity reference targets did you need to modify? And what did you modify on it?
Comment #34
superlolo95 CreditAttribution: superlolo95 commentedHello
Thanks for the reply.
My custom module works on certain type of node.
I had to modify the ConfigEntityReference mapper. I change the parameter from entity_reference to config_entity_reference.
Otherwise, my module is using the ConfigEntityReference mapper instead of the EntityReference mapper.
My type of node is build as below
node person:
--parapgraph work
------node establishment
The 3 step is where I am having troubles. The ConfigEntityReference mapper is used instead of the EntityReference mapper. Should I "disabled" the ConfigEntityReference mapper.
I do not get how feeds choose what mapper should be used.
Comment #35
MegaChriz CreditAttribution: MegaChriz as a volunteer commented@superlolo95
Do you use additional modules for importing paragraphs? If so, which one? Maybe there’s an issue with that module that’s causing to using the wrong FeedsTarget plugin.
Do you import paragraphs separately (one feed type for paragraphs + one feed type for nodes) or alongside with nodes (one feed type for nodes and paragraphs combined)?
Comment #36
superlolo95 CreditAttribution: superlolo95 commented@MegaChriz,
I use a dedicated custom module to perform the import.
This import is done in a single shot, by this I mean a node (person) and a the associated paragraphs (work) are imported simoustaneously.
The nodes establishments are already existing and imported separately.
So my CSV lines (person+ work) are explode user tamper to extract the individual paragrahs (work) data.
What I do not get is how feeds select the mapper if there are multiple mappers for the entity_reference field type.
What I though was that feeds looks into all the existing mappers and take the first one that matches the current field type. And here as there 2 mappers with field_types = {"entity_reference"}, feeds does not know which one to select.
But I think I am missing something.
Comment #37
MegaChriz CreditAttribution: MegaChriz as a volunteer commented@superlolo95
\Drupal\feeds\Plugin\Type\Target\FieldTargetBase::targets()
, each field on the entity type is checked if it matches what is defined in the annotation for "field_types" for the current FeedsTarget plugin:::prepareTarget()
gets called. Only if that returns something, a target gets added to the list of available targets.\Drupal\feeds\Feeds\Target\EntityReference::prepareTarget()
only returns something if the entity type is a content entity type. See theentityClassImplements()
call.\Drupal\feeds\Feeds\Target\ConfigEntityReference::prepareTarget()
only returns something if the entity type is a config entity type. Again, see theentityClassImplements()
call.\Drupal\feeds\Plugin\Type\Target\FieldTargetBase::targets()
.UserRole::targets()
completely overridesFieldTargetBase::targets()
. It defines a target for each field that references entities of type 'user_role'.Does this clear up some things for you?
Comment #38
superlolo95 CreditAttribution: superlolo95 commentedthanks a lot for the very detailed answered!
I will have a look at it, I think this will solve my issue.