Migrate the Gender field from Drupal 7 to Drupal 8, using the data from https://github.com/drnikki/open-demographics/blob/master/doc-source/ques... for the gender options.
We're starting small for this, so for now we'll be leaving off the "Other" option and tackling that in a separate issue.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | gender-chosen-widget.png | 3.04 KB | alexdmccabe |
| #15 | gender-field-contact-form.png | 56.57 KB | rootwork |
| #15 | gender-field-taxonomy-add.png | 69.32 KB | rootwork |
| #15 | gender-field-comment-add.png | 68 KB | rootwork |
| #15 | gender-field-user-view-unlimited.png | 37.3 KB | rootwork |
Comments
Comment #2
krismaye commentedThis is a work in progress
Comment #3
krismaye commentedComment #4
alexdmccabeComment #5
alexdmccabeI went ahead and did the boring work of adding the additional options from the gender list to the widget. Looking at it now, it does occur to me that perhaps a select/multi-select would be better than radios/checkboxes, just due to the length of the widget.
Screenshot and patch files are attached.
@krismaye - To apply a patch, first you'll need to reset your local repository:
And you might also need to remove the
srcdirectory, since it isn't being tracked yet:Then you should be able to apply the patch with:
If that doesn't work, which sometimes it doesn't because git is weird, try using:
That should get you up to date with the changes I've made. From there you can proceed as normal and create an interdiff between my patch and the next patch you create.
If you run into any trouble or if you're just not comfortable with doing any of that, feel free to reach out to me on Slack.
Comment #6
krismaye commentedI agree that a multi select may be better with this many options. I also wonder if we might want to put the options in alphabetical order... it might make it easier to find the one(s) you're looking for?
Comment #7
mradcliffeWe could also add some default CSS to layout the options horizontally on desktops.
And maybe an additional widget that integrates with chosen?
Comment #8
alexdmccabeI think Chosen should just integrate out of the box if we use a select/multi-select field, shouldn't it?
Comment #9
alexdmccabeWe could look into adding an optional dependency on the Chosen module that, if it's present, automatically configures the field to use Chosen? Maybe even make that configurable, and perhaps on by default, but have it so users can disable it if they'd prefer to not use Chosen for it.
Comment #10
alexdmccabeOkay, I figured it out. I kept it based on an options widget, but changed it to a select widget. I also had to do some tweaking to the
FieldTypeclass get it to accept the values, instead of not storing them or complaining that the entered values were invalid.Comment #11
volkswagenchickI applied the patch in comment 10 locally with no issues. I was able to add the gender field to a content type. I allowed multiple values and when entering content, multiple values could be selected, and then multiple values displayed on the saved node.
I also maybe wonder about putting the gender choices in alphabetical order as suggested in Comment 6. I will let others weigh in.
Thanks for all the work on this module!!
Comment #12
alexdmccabeI'm inclined to leave them in the order that they're in.
Iwe pulled them straight from the Open Demographics project's gender page.Uploading a new patch that fixes some coding standards issues. Unless anybody has any objections, I think this is about ready to go.
Comment #13
mradcliffeIt is possible that ListStringItem still might be set explicitly as @internal or considered internal as part of #2873716: Add @internal to core classes, methods, properties to Plugins per d8 backport policy. I think there's a strong case for ListStringItem to be public API, but if the goal is to implement a field type maybe StringItemBase is the best (if you can make make it work). As an example, I was put in a hard place extending from a class that was then marked internal when a core API changed so my module broke between minor releases (it wasn't explicitly marked as @internal yet).
That said I don't think it's a blocker as we can implement it later. Maybe an @todo about swapping out?
Adding either a FunctionalJavascript test and/or a Unit test would be a good next contributor task for someone to pick up.
Comment #14
alexdmccabeI switched it over to
ListItemBase- I assume that's what you meant, sinceListStringItemextendsListItemBase, and bothListItemBaseandStringItemBaseextendFieldItemBase, so usingStringItemBaseseems like it wouldn't be appropriate, unless I'm missing something here.It was an easy change to make, so I figured we should knock it out now instead of leaving it as a to-do.
For what it's worth, I do think it's a little silly, though - one of the benefits of the switch to the OOP structure is being able to extend and override classes, but not these classes, because reasons. So copy and paste a bunch of code out of those classes and into your classes. That was literally the solution: copy and paste the extra methods out of
ListStringItemand into theGenderfield type class./shrug
Re: tests, we have an issue for that already, #2960781: Add tests for Drupal 8 field.
Comment #15
rootworkI tested this field on simplytestme and it looks great! I tested adding the field on nodes, user profiles, comments, taxonomy terms, and the web form. I tested adding a field with a cardinality of 1 and of unlimited. I tested adding a required and a not-required field.
Screenshots:
↑ Choosing the gender field in field selection. I love the "Diversity & Inclusion" category, especially since we might expand to support more types of fields!
↑ Completing the field on a node edit form, with only one value allowed, non-required field.
↑ Viewing the node with one value.
↑ Completing the field on a user profile form, with multiple values allowed, required field.
↑ Viewing the user profile with multiple values.
↑ Adding a comment with a gender field.
↑ Adding a taxonomy term with a gender field.
↑ Using the (core) website contact form with a gender field.
I don't feel qualified to evaluate the code, so I will leave this as "needs review" in case someone wants to do that. However, given that the module clearly works, if no one can review it in the near future, I think it's ready to be at least released as an alpha. If someone wants to sign off on reviewing the code as well, I think we could jump straight to a release candidate.
Possible follow-up issue (non-release-blocking): Provide field formatter(s) when the field has multiple values offering the option of comma-separated values (at least), other-character-separated-values, UL/LI, maybe OL/LI (ranking ones genders?). Right now each value is just in a DIV.
Comment #16
alexdmccabeI tested Chosen, and we don't need to do anything to integrate with it. With the default Chosen settings, it enables it on all select fields, so it works right out of the box.
I'm okay with merging this in and calling it alpha1. Anybody have any objections?
Comment #18
alexdmccabeI went ahead and merged it in since it works and there's at least 3 other issues pending on it. If we find problems with the work done so far, we can open new issues for those.
Thanks everyone!
Comment #19
rootworkPosted the follow-up issue I mentioned in #15 here: #2964797: Provide display field formatter when multiple values are selected