Comments

alexdmccabe created an issue. See original summary.

krismaye’s picture

StatusFileSize
new10.35 KB

This is a work in progress

krismaye’s picture

StatusFileSize
new10.52 KB
new3.42 KB
alexdmccabe’s picture

Issue summary: View changes
alexdmccabe’s picture

StatusFileSize
new12.06 KB
new1.85 KB
new14.13 KB

I 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.

The gender field widget being created by this module, with 31 radio buttons, creating a very lengthy widget.

Screenshot and patch files are attached.

@krismaye - To apply a patch, first you'll need to reset your local repository:

# Make sure you're in the gender module directory first!
git reset
git checkout .

And you might also need to remove the src directory, since it isn't being tracked yet:

# No really, make sure you're in the gender module directory first!
rm -rf src

Then you should be able to apply the patch with:

git apply gender-migrate-field-2960779-5-8.patch

If that doesn't work, which sometimes it doesn't because git is weird, try using:

patch -p1 < gender-migrate-field-2960779-5-8.patch

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.

krismaye’s picture

I 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?

mradcliffe’s picture

We could also add some default CSS to layout the options horizontally on desktops.

And maybe an additional widget that integrates with chosen?

alexdmccabe’s picture

I think Chosen should just integrate out of the box if we use a select/multi-select field, shouldn't it?

alexdmccabe’s picture

We 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.

alexdmccabe’s picture

Status: Active » Needs review
StatusFileSize
new11.84 KB
new8.81 KB

Okay, 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 FieldType class get it to accept the values, instead of not storing them or complaining that the entered values were invalid.

volkswagenchick’s picture

I 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!!

alexdmccabe’s picture

StatusFileSize
new12.11 KB
new838 bytes

I'm inclined to leave them in the order that they're in. I we 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.

mradcliffe’s picture

+++ b/src/Plugin/Field/FieldType/Gender.php
@@ -0,0 +1,54 @@
+class Gender extends ListStringItem {

It 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.

alexdmccabe’s picture

StatusFileSize
new12.94 KB
new1.79 KB

I switched it over to ListItemBase - I assume that's what you meant, since ListStringItem extends ListItemBase, and both ListItemBase and StringItemBase extend FieldItemBase, so using StringItemBase seems 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 ListStringItem and into the Gender field type class.

/shrug

Re: tests, we have an issue for that already, #2960781: Add tests for Drupal 8 field.

rootwork’s picture

I 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:

 Manage fields form
Choosing the gender field in field selection. I love the "Diversity & Inclusion" category, especially since we might expand to support more types of fields!

 Node edit form, single cardinality, non-required field
Completing the field on a node edit form, with only one value allowed, non-required field.

 Node view, single cardinality
Viewing the node with one value.

 User profile form, unlimited cardinality, required field
Completing the field on a user profile form, with multiple values allowed, required field.

 User profile (view), unlimited cardinality
Viewing the user profile with multiple values.

 Add comment
Adding a comment with a gender field.

 Add taxonomy term
Adding a taxonomy term with a gender field.

 Website contact form (core contact module)
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.

alexdmccabe’s picture

StatusFileSize
new3.04 KB

I 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.

The gender field widget being created by this module, and then further enhanced by the Chosen module. Chosen is working on the field as expected, with 3 values entered.

I'm okay with merging this in and calling it alpha1. Anybody have any objections?

alexdmccabe’s picture

Status: Needs review » Fixed

I 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!

rootwork’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.