0

I'm developing a drupal module and there's a problem. I need to make a content type with some fields and one of them should have list with string values. But when I try to create content and choose new content type I created, I see list and there are values contains first symbol of the string that I need.

coursebook.info.yml

name: Course Book
description: Course book
type: module
core: 8.x
package: Course book module

field.storage.node.field_disciplines.yml

langcode: en
dependencies:
  enforced:
    module:
    - coursebook
  module:
  - node
id: node.field_disciplines
field_name: field_disciplines
entity_type: node
type: list_string
settings:
  allowed_values: { "1":'A', "2":'Bb', "3":'Cccc'}
  max_length: 1000
module: core
locked: false
cardinality: 100

field.field.node.coursebook.field_disciplines.yml

langcode: en
dependencies:
  config:
  - field.storage.node.field_disciplines
  - node.type.coursebook
id: node.coursebook.field_disciplines
field_name: field_disciplines
entity_type: node
bundle: coursebook
label: 'disciplines'
description: 'Type disciplines here'
required: false
default_value: 'example'
settings: { }
field_type: list_string

core.entity_view_display.node.coursebook.default.yml

langcode: en
status: true
dependencies:
  config:
  - field.field.node.coursebook.field_year
  - field.field.node.coursebook.field_semester
  - node.type.coursebook
id: node.coursebook.default
targetEntityType: node
bundle: coursebook
mode: default
content:
  field_year:
    label: hidden
    type: string
    weight: 0
    settings: {  }
    third_party_settings: {  }
  field_semester:
    label: hidden
    type: string
    weight: 1
    settings: {  }
    third_party_settings: {  }
  field_disciplines:
    label: hidden
    type: string
    weight: 2
    settings: {  }
    third_party_settings: {  }

core.entity_form_display.node.coursebook.default.yml

langcode: en
status: true
dependencies:
  config:
  - field.field.node.coursebook.field_year
  - field.field.node.coursebook.field_semester
  - node.type.coursebook
id: node.coursebook.default
targetEntityType: node
bundle: coursebook
mode: default
content:
  field_year:
    type: string_textfield
    weight: 0
    settings:
      size: 30
      placeholder: 'example'
    third_party_settings: {  }
  field_semester:
    type: string_textfield
    weight: 1
    settings:
      size: 30
      placeholder: 'example'
    third_party_settings: {  }
  field_disciplines:
    type: string_textfield
    weight: 2
    settings:
      size: 30
      placeholder: 'example'
    third_party_settings: {  }
hidden: { }

And what I see - enter image description here But i shuold see this list:

allowed_values: { "1":'A', "2":'Bb', "3":'Cccc'}

There are only files that describe problem field. I hope you understand my problem. I develop my module using this manual: https://medium.com/touch4it/custom-content-type-with-custom-fields-for-your-drupal-8-module-9478fd018f76

2
  • Have you imported configuration, and cleared cache?
    – user72672
    Jul 12, 2019 at 11:38
  • When I tried this in 8.7.3, my allowed values setting looked like this: allowed_values: - value: '1' label: a - value: '2' label: banana - value: '3' label: cabbage What version of drupal are you using? Jul 12, 2019 at 15:46

1 Answer 1

1

You need to have the allowed values settings in the following format:

allowed_values:
  -
    value: '1'
    label: A
  -
    value: '2'
    label: 'Bb'
  -
    value: '3'
    label: Ccccc

The quotes don't matter for single word strings. I hope this helps.

1
  • Yes! Thank you very much!
    – ectuser
    Jul 16, 2019 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.