Problem/Motivation
When going to "/subscription-management-service/sync-user/[user-id]" the following error will appear:
InvalidArgumentException: Field field_subman_external_id is unknown.
Having a look in the README, apparently the user field has to be created manually. This should be done automatically on installation
* Ensure the field user.field_subman_external_id exists as type text (plain).
* Ensure the field user.field_subman_sync exists as type text (plain, long).
Steps to reproduce
Proposed resolution
Automatically create both fields on the user on installation.
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork subman-3366167
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
anybody@Grevil: Thanks, I totally agree with the auto-creation, especially because also the machine name of the field is hard-coded. Otherwise, it should be done the other way around as a setting, where you can select the appropriate field, but I think hard-coding the name is okay for this special case in the module.
Installation of the field should be simple by creating the field and putting the config export into the install directory (after UUID etc. cleanup).
The steps should be removed from the README then.
Comment #3
anybodyGo for it, should be simple using
drush cexSadly drush decided against a uuid removal option: https://github.com/drush-ops/drush/issues/3468
Comment #5
grevil commentedDone, please review!
Comment #6
anybodyOkay, the code is ready for test now, I made the fields locked and dependent on the subman module.
The
field_subman_syncisn't really clear to me. I guess it's a kind of user data storage, but we should have a closer look, what it does. If it's clear for example, that it will always store JSON content, it might be better to introduce a dependency on https://www.drupal.org/project/json_field and use a JSON field, instead of a string. Once #3343634: Add "json" as core data type to Schema and Database API is solved, we might use JSON as core data type.Also it might be discussable if a field is the right choice here, or if it should better use User Data:
https://www.webomelette.com/storing-user-data-such-preferences-drupal-8-...
Comment #7
grevil commentedIndeed @Anybody, the field is used to store json data.
This is done through "storeSyncData()" inside "/src/SubmanSync.php":
Let's implement it and add the dependency as said in #6.
Comment #8
grevil commentedAlright, done! The type of the fields isn't checked anywhere, and accessing "/subscription-management-service/sync-user/1" does not throw any errors! Please review!
Comment #9
anybody@Grevil: Are both fields present as expected in the UI?
Comment #10
anybodyWell done, RTBC!
Comment #12
anybody