Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Now that we have #1445224: Add new HTML5 FAPI element: color landed for FAPI, we should really add the ability to have a color field type. It should probably have one column 'color' of type SQL varchar(7), and a field widget using the new HTML5 FAPI type, and a default formatter of just 'plain text' that outputs the raw value.
Based on #1675000: Allow selecting an alpha channel for the color FAPI element we may add support for an 'alpha' column via a field setting (since it changes the field schema).
Comment | File | Size | Author |
---|---|---|---|
#26 | 1740438-nr-bot.txt | 9.29 KB | needs-review-queue-bot |
#3 | color_field-1740438-3.patch | 6.01 KB | plopesc |
#2 | color-field-1740438.2.patch | 4.72 KB | larowlan |
Comments
Comment #1
Dave ReidComment #2
larowlanFirst go
Comment #3
plopescHello
After #1668332: Add an E-mail field type into core, providing a patch where the field architecture is based in a separate submodule.
Tests has been included in this approach.
Regards
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentedI think we should have a use case before adding it, or else it stays in Contrib. Add 'Favorite color' to the User entity? :)
Comment #5
swentel CreditAttribution: swentel commentedYeah, I guess this is D9 material
Comment #6
catchComment #7
JurriaanRoelofs CreditAttribution: JurriaanRoelofs commentedAs a theme/site-builder tool developer I can think of use cases for this. color fields would be nice to implement per-node, per-context, per-role etc. design variations to theme regions or dynamic content.
Comment #12
Pere OrgaThe module on its own would not be very useful. But whether it is in core or in contrib, it would allow to build solutions such as the ones described in #7. The only advantage I see of having it in core would be that contrib modules and themes would be able to use it immediately. Maybe that's why the color element was added to Form API.
There are at least 3 different modules that provide a color field type:
https://www.drupal.org/project/jquery_colorpicker (7.x, 8.x)
https://www.drupal.org/project/color_field (7.x, 8.x)
https://www.drupal.org/project/colorfield (only 7.x for now)
Unfortunately all of them are more complex, add more stuff and/or require using external libraries. Ideally, if these modules needed to exist they should be extending the Form API/field core's functionality.
About adding it as a contrib project: @larowlan @plopesc have you considered creating the project? I could also create it, as I need this functionality right now and I was thinking to use it for future 8.x versions of https://www.drupal.org/project/field_group_background_image. By the way, I see that the name "color_field" is already in use by the existing Color Field contrib module (and has 8.x releases...)
Comment #13
plopescHi Pere,
That'd be great and I would be happy to help with that, but as you pointed we now have the namespace issue. We cold use "rgb_field" as less bad option.
Other option would be to try to contact with color_field/colorfield maintainer and ask them to create new branches to use as color API module and then create multiple submodules adding extra features or using external libraries.
Comment #14
Pere OrgaHi,
Even if that may be possible, I was wondering if having this new module as a separate project would be a better option. Nowadays all major browsers support input type color; if a polyfill is desired to add support for older browsers, that polyfill should work for all form fields, not just Field API fields, and therefore it would make sense to have it as an external project. That way the polyfill could be used for a broader audience.
Adding external libraries would harden maintenance, and that would favor only one or a few libraries, not necessarily the best ones.
By the way
rgb_field
name sounds acceptable to me.Comment #22
Pere OrgaFWIW, I see that now there is Color API contrib module (used by Jquery Colorpicker), and that Color Field also gained input type=color support.
Comment #26
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #27
catchThere are about 30,000 Drupal 8+ sites using https://www.drupal.org/project/color_field, which is a fair amount, but I'm not sure it's enough to justify adding the field type to core. We're already considering moving telephone to contrib since that isn't widely used. Moving this to the core ideas queue for new feature evaluation.