Closed (fixed)
Project:
List field predefined options
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 Dec 2015 at 23:10 UTC
Updated:
21 Jun 2023 at 13:39 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
stmh commentedAs a workaround export your config, and set the
allowed_values_functionto your custom function in thefield.storage.<entity>.<field>.ymlExample:
custom_field_example_option_listis the function which gets called for all available option.Comment #3
joachim commentedHere's a D8 version of this.
Instead of an info hook like on D7, the option lists are plugins.
Works fine, just a bit of UI polish needed in the field storage form which I don't have time to do right now.
Comment #4
decipheredHi @joachim,
I put your code in a repo (so I can potentially use it and/or contribute to it), happy for you to do yourself though so you get the correct credit; https://github.com/Realityloop/list_predefined_options
Comment #5
deciphered#2828295: [list_predefined_options] List field predefined options
Comment #6
jibranAnyone interested in moving it to core #1909744: Allow adding predefined lists to the options fields via plugins?
Comment #7
markus_petrux commentedHi all!
Any chance to get a release for the D8 version so it can use installed with composer like other Drupal modules?
Thank you!
Comment #8
etroid commentedSeconding creating a D8 release on d.o so we can install it with composer!
Comment #9
stmh commentedAny news on this?
Comment #10
d70rr3s commentedAs commented above has been included as patch to core on #1909744-22: Allow adding predefined lists to the options fields via plugins, needs re-rolling against 9.2 branch, I'll try to update the patch this weekend but all help is welcome. The patch is working for 8.9 core branch (I'm using it in several sites).
Comment #11
stmh commentedthanks for the link, seems I missed this discussion!
Comment #12
joachim commentedI've applied for comaintainership of this project to make the D8/9 version official.
Comment #13
joachim commentedI've committed this, and made some further fixes.
One major change I made is that list plugins must now specify which field types they work with. Otherwise, you could use the US states plugin with a list_integer field, and then you'd be trying to save strings into an int DB field -- I don't know if form validation would just block you from ever saving the entity, or whether you'd crash the DB, but either way, not good!