Hi,

any plans for a drupal 8 release?

CommentFileSizeAuthor
#3 list_predefined_options.zip14.55 KBjoachim

Comments

stmh created an issue. See original summary.

stmh’s picture

As a workaround export your config, and set the allowed_values_function to your custom function in the field.storage.<entity>.<field>.yml

Example:

uuid: 0abecafb-c91a-4a9d-b5c2-79fc3749b3e6
langcode: en
status: true
dependencies:
  module:
    - node
    - options
id: node.field_example
field_name: field_example
entity_type: node
type: list_integer
settings:
  allowed_values_function: custom_field_example_option_list
module: options
locked: false
cardinality: 1
translatable: true
indexes: {  }
persist_with_no_fields: false
custom_storage: false

custom_field_example_option_list is the function which gets called for all available option.

joachim’s picture

Status: Active » Needs review
StatusFileSize
new14.55 KB

Here'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.

deciphered’s picture

Hi @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

deciphered’s picture

jibran’s picture

markus_petrux’s picture

Hi all!

Any chance to get a release for the D8 version so it can use installed with composer like other Drupal modules?

Thank you!

etroid’s picture

Seconding creating a D8 release on d.o so we can install it with composer!

stmh’s picture

Any news on this?

d70rr3s’s picture

As 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).

stmh’s picture

thanks for the link, seems I missed this discussion!

joachim’s picture

I've applied for comaintainership of this project to make the D8/9 version official.

joachim’s picture

Status: Needs review » Fixed

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

Status: Fixed » Closed (fixed)

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