41. 配置系统Configuration(三):配置schema与类型化

龶龲龮龪龦龣龟龞龝龶龙龕龓龐龌龦龣龟龈龇龅龃齿齾齼齻 API 龞龝齰齯齭齫齨齦龙龟龞龝齣齢龅齞齝齛齘齗龪齖齕龅龙齔齛龐齐龅龶齌齊齉龙齈齇齆齅齃齀鼼

齼齻龃齿龮

鼺鼶鼲鼯齔鼫鼨鼥龙鼣鼡龅鼟龃鼞鼜齖齼龙鼛鼗鼓鼐鼌鼋鼇鼟鼃鼂龙黾黽黹鼃鼂黶鼗鼓黲鼟黰龟黬黫龙黧黥黣龃黟點黛黗龙黛齭黖黓黒黏龅鼲鼯龙黌黋黊黈黆黃黀黽麽鼲鼯麺麷龅鼣鼡麴鼡麲麱鼗鼐麰鼌鼟麯麫龙黽鼟麩麦龅黆麤黌黈麣龪齼麟鼲鼯麝龙齔麛齛齼齻龅龃齿龙黰麙麕麔麒麷麏齼鼞鼇龅黲鼟黰龟齼齻龃齿龙麋麇麃齦黀麁鹽黋黋鼇鼇鹹鹵龅龃齿鹴鹳鹱鹰鹬鹩麷鹦鼋鼇鼟齼齻龃齿龙鹥鹤鹡鹠齅鹜鹙鹘鹔鹓龙麷鹒龃齿麛齊鹎齼齻龅鹊鹇鹴鹄鹃鸿鹥鸽鹓龙鸺鼇鼣鸸麛鸵鸳鸰鸬齃鹒龙鸵鸨鼓鸤齼齻鸡鸠鸜鸘鸕鸔鸔鼼 drupal 黛鸂鹒鷿鷻龅龃齿齾鷷黆龙龈鷶鷲麷齅鹩齼齻龃齿龮

黰龟龃齿龮

php 鷯龲鷬鷫鹒黰龟龅齼齻龃齿龙 drupal 龪鷩黰麙齕黛鼌黗鷷黆鹒龈鷶麺鷧龅黰龟齼齻龃齿龙龃齿齾齼齻鷣鷡鷠鹬鹒黽黹黰龟龃齿龙齅鷞麤龅鷜鸽鷬鷫鷘鷔龙黰龟龃齿麷龮 boolean email integer float string uri mapping sequence 龙鶰黀鶮齅 oop 鷞麤龅鷜鸽鶫龪龙麃龃齿齾鷣鷡鷬鷫龅龃齿龃鷷鶨齾黾鶤鼼

鶠鶟鶛鶙龃齿龮

鷞黰龟龃齿龅鼌鼟鶠鶟鶛鶙龙齅鶘鶗鷯鹔鹄鹠鸘鸕鶓鸔鸔

鶐鶍鶛鶙龃齿龮

齅龶麔鷬鶌龅龃齿鷣鶍黾鹽龅鹹龃鶐鶍龃齿龙麏齼鼞鼇龅鶠鶟黰龟龃齿鶊齻齼鶇鸜鼟龃麁鹽鹒齼鶇鶅鼺龅鹹鼟龃齿龙齅 mapping sequence 鷜鸽黛鸂鷣鶍龙鸨麰鼃鼂鶄鹽鶃黫龙鶃黫鶂鶄鹽鼨鼥鼇鵿龅鼲鼯鼌鵼

鵹齅齕鵸鼺龃龅龃齿鵶鹡麷鵴鼟鹊鵱龃齿龮

Undefined 龮鵪鵩鵨鹘鹔龃齿龙鵤麷鵡鶘鹘龃齿龅齼齻鹳鹱鶃鵟鵜龃齿鵛

Ignore 龮鵪鵩鵙鼞鵖鵕鷔齼齻龃齿龅鵑鵐齅鵜龃齿鶗鵍鵪鵩

drupal 龈鷶鷲鷞齼齻龃齿龅鵊鵆齛鵄龪 Schema 鵀鷡鷲龅龙龃齿鵊鵆鹒齼齻鴼鶄龙鴹鼐齼齻龅鼃鴸鴷龙麃龃齿齾齼齻鷣鷡鴵鴲鷷黆齼齻龅龃齿齾鵕鷔龙 Schema 鹠鸘鸕麏鹥鸽鸜鴯鸽鸜鹵鴭鸜鹽鴫鸜鼜鴧鸜鴤齀鸜鴠鴞龙黽麝麏鴚鵆鷜鴗龙鸘鸕麏鴔鹥鸽鴑龙鹥鸽鵀鷡齅 yml 鴯鸽鴋鶫龙鶫鵄龪鹥鹤鴊鴈鴆龅 config\schema 鴁鳽鷲龙齰齅 schema 鳺麏鵀鷡鳶麇鳳鹴鼞齛鶛鶙鳶鹓鼼龪鳱鳭龮 core\ config\schema 鷲齛龈鷶鴈鴆鷬鷫龅齼齻龃齿龙齔鳩鳨鹒黰龟龃齿龙鹘鹔黰龟龃齿麇鹠齅鷔齦鷣鶍鳦齖鶰龃齿龙鼌鳤鹘鹔鹒鼌麽龃齿龙齔鼫麛鹠齅鷔鵜龃齿鹜鹙鷣鶍鳣麣鳦齖鶰黖鼺黖鶐鳡龅齼齻龃齿鼼

龪鵟鳟龈鷶鷲龙鳛鼌麽鵟鳟鷞麤鶮鹠齅鳙齖鹘鹔麏鼌鼟齼齻龃齿龙鸨鳘鵤麷鹘鹔齇鳙鳔麏 Undefined 龃齿龙鳐鹩鶤鳌鳌鸨鳊鹘鹔鵟鳟龃齿龙鳉齘齗鵟鳟 Schema 鵀鷡鼼

schema 鹘鹔龮

鹥鸽 Schema 鵀鷡 yml 鴯鸽鴋鶫龪鹥鹤龅 config\schema 鴁鳽鷲龙鳅鳁鳀鲾鷷鲺龙鲷鳶鷜鸽麏龮

鹥鹤鳶 + 鶃龃鳶 + .schema.yml 鴑龙鸨 core.entity.schema.yml

鼌麽鹥鸽鵀鷡鷲鹠齅鹘鹔鼇麽鵟鳟鷞麤龅龃齿龙鵙鼞鷧鴞鶃龃鳶鵑鹠齅鲯鲮龙鸨龮 contact.schema.yml

鲭鲪龮 schema 麇鳳鼞齛鲩鲨龅龙鲥齛鼌鼟鳀鲾鷷鲺龙鲣 .yml 鶛鶙齛龐齐龅龙龈鷶齅龪鹥鹤龅 config\ schema 鴁鳽鷲鲟鵊 yml 龃齿鵀鷡龅鷜鸽鶤鲜鲛 schema 鵀鷡 龙鲘鷩鼞鴞龪鵜鴁鳽鹩鵄鳟齞齝鲕 schema yml 鵀鷡鼼

龪鹥鹤龅 config\install config\optional 鵀鷡鲔鷲鼌麽鵟鳟鵀鷡麛齛鼌麽鵟鳟鷞麤龙鼞鲓鶛鶙鳶龅鵀鷡鳶麛齛鵟鳟鷞麤鳶龙麰鵑黌齛鵜鵟鳟鷞麤龅龃齿鳶龙鼇麽鵟鳟鷞麤龅龃齿鹘鹔鹠齅鵄鳟龪鼌麽 schema 鵀鷡鷲黛鸂龙齅鵀鷡鳶鹴龃齿鳶鹓鳺麏 yml 鴯鸽龅鶊鲏鳶龙鵜鲏鳶龅鲍齛鼌麽齼鷣龙鵜齼鷣麛齛黽麽鵟鳟鷞麤龅龃齿鹘鹔龙龃齿鹘鹔麷鸨鹩黽黹鲏龮

Type 龮鵟鳟鷞麤鷲鲍龅龃齿龙鲆鹠齅齛黰龟龃齿黌鹠齅齛鳣麣龃齿龙鷿鷻鲃麇

Label 龮鲍鵊鵆龙齦鼞鼌鹘麛齛鵟鳟鵪鶟龅 label

Translatable 龮鵪鶗鵜龃齿齛齈鹠鸘鸕龙鲍麏 true 鹄鼞鲀鳟龙鼞鲀鳟鹳鹱麏鼞鹠鸘鸕

Nullable 龮鵪鶗鲍齛齈鹠齅麏 null 龙鸨鼞鲀鳟龙鹳鹱鼞鵖麏 NULL

Class 龮鷔鼐鷠鹬鵜龃齿龅龃齿龃 鱶鱲鹘龃鳶龙鲃龃齿齾齼齻 API

definition_class 龮鵜龃齿鹘鹔龃龅鱶鱲鹘龃鳶龙鲃龃齿齾齼齻 API

translation context 龮鸘鸕齕鹩鵀龙鹠鱬龅龙鲃龟龈龇龅鸘鸕龞龝

mapping 龮鸨鳘龃齿鵡鶘鹘麏 type: mapping 龙鱧鹠鵖麷鵜黫鲏龙齖鲍麏鱥鱣齼鷣

sequence 龮鸨鳘龃齿鵡鶘鹘麏 mapping sequence 鵑龙鵜鲏龅鲍麏鱟龇齼鷣鹴鴋鶫鱞麰龃齿龅鱥鱣鹓

type 鴹鶓龅鲍鱝黒鶐鳡龙齛鼌麽麟鱛鱗鲍龙鸨鳘鵨鹘鹔 type 鴹鶓龙齔鼫齖 鲍麏鵜龃齿鼓鱕 龅龃齿鳶龙鱒鱎鷧鴞鵡鲀鳟龙鲍麏龈鷶鷲鶫龪龅鹘鹔龃齿鹴鴊鱊鳟鱉鱆龙龪麰鼌鹥鸽鵀鷡鷲鹠鵄龪龟龃齿鹘鹔龶黌鹠齅龪麇龙黌鹠齅鶫龪鼐鼞麰鹥鸽鵀鷡鷲鹓龙龈鷶鱄鱃龃齿鹘鹔鵑鳙齅鷩麏鱂齻黛鸂鹘鹔龅鰿麲鶍齰龙鷘鷔鸨鹩鶍齰鷜鰾龮

NestedArray::mergeDeepArray([$merge, $definition ], TRUE)

齼鷣鶍齰鲃龟龈龇齼鷣鰠鳺龞龝龙 $definition 麏鵙龶鹘鹔龙 $merge 鵪鵩 type 鴹鶓鶘鹘龅龃齿鹘鹔龙鸨鳘麷麰鳶鲏齇鵙龶鹘鹔鰜鰚 $merge 鹘鹔龙麺齅鵙龶鹘鹔齛鰗龌龅龙鶍齰鰠鳺鼌鰖鰿麲鶌黰龟龃齿鹴黰龟龃齿鵤麷 type 鴹鶓鹓龙鰿麲鶍齰麇 type 鴹鶓鲍麏鼓鱕龙鶍齰鵩鶨鸨鹩龮

string:
  label: 'String'
  class: '\Drupal\Core\TypedData\Plugin\DataType\StringData'
label:
  type: string
  label: 'Label'
  translatable: true

龪鱄鱃 label 龃齿龅鹘鹔鵑黊鰐鶌龮

label:
  type: label 
  label: 'Label'
  translatable: true
  class: '\Drupal\Core\TypedData\Plugin\DataType\StringData'
  definition_class: '\Drupal\Core\TypedData\DataDefinition'

齖鷲鸨鳘鶍齰麇鵤麷 definition_class 鰎龙黊鵡鰋黓鹳鹱鲍龙鸨齕麺鵩鼼

麷鵑鵐鰇黹龃齿鹘鹔龅 type 鲍鱂鰅鼐鰂鷞麤龅龃齿鹄鵟鳟齼齻鷲龅鰇鵟鳟鲍龙黌麛齛鰀 type 龅鱃鲍鼞齛鯾鯺龅龙黾齛鷧鴞鯹鸂鵑鶊齻鱂鰅黛鸂鼜鯸龙黽鯶麏鸤鯺龃齿龙鸤鯺龃齿齛龪 type 鴹鶓鲍鷲鷘鷔鹊鹘龅鯳鶇鳶龙鷔鶌龅鯳鶇鳶齅鷜鳨鯱鳩鳨龙鹠齅麷鼇麽鷜鳨鯱鯮龙龪鶟麽鷜鳨鯱鷲鸨鳘麷鼇麽鯳鶇鳶鹠齅鷔鯫鯱鶃鯩龙 鷜鳨鯱鷲鼞鹠齅麷鯳鶇齅麏龅齞齝龙鸨龮 type: '[%parent.%parent. %t ype].third_party.[%key]'

鯳鶇鳶麷鵴鼺龃龮



鵟鳟齼齻鷲龅鰇鼌鵟鳟鲏鳶龮鸨



[%parent.field_type]



鷲龅



field_type



龙鵪鵩鵟鳟齼鷣鷲齕鼌鯟齼鷣鷲龅



field_type



鲏龅鲍

鹊鵱鯝鷔鯳鶇龮

%parent 鯝鷔鶌齼鷣鷲龅齕鼌麕鯟

%type 龐齐鴊 %parent 鯜鷔龙鵪鵩鰇鼌麕鯟齼鷣龅龃齿龙鲭鲪龪鷲鳨鯱麝 %type type 齛鼞鼌鹵龅鵴鼟鯳鶇龃齿

%key 龟龃齿齼齻龪鰂麕齼鷣鷲龅鲏鳶龙龪鱥鱣龃齿龃鷲黌麛齛 $parent->getName()

龶鵀鷬鶌鸨鳘鶘鹘鹒 Type 鴹鶓龅鲍龙齔鼫黊鲛鶌齦黛鸂鹘鹔鶍齰龙鸨鳘鲛鼞鶌鷞鵕龅龃齿鹘鹔龙鳙黛鸂鯔鯑鲜鲛龙鱂齻鲍龅麕鯟黛鸂龙鸨鹩龮

鸨鳘鲜鲛龅龃齿麏龮 breakpoint.breakpoint.module.toolbar.narrow 龪鲛鼞鶌龅鸸鯊鹩龙鱂鯈鯄鯃鼌鹩鲍龮

        breakpoint.breakpoint.module.toolbar.*
        breakpoint.breakpoint.module.*.*
        breakpoint.breakpoint.module.*
        breakpoint.breakpoint.*.*.*
        breakpoint.breakpoint.*
        breakpoint.*.*.*.*
        breakpoint.*

龃齿鳶齛麷鴫齇龅龙齅鯫鯱鶃麕鯟龙黌鹠齅鷘鷔鮾鯱龙鸨龮

鲜鲛 block.settings.system_menu_block:footer 龪鲛鼞鶌龅鸸鯊鹩龙鱂鯈鯄鯃鼌鹩鲍龮

        block.settings.system_menu_block:*
        block.settings.*:*
        block.settings.*
        block.*.*:*
        block.*

麃鷩黌鹠齅鳌鳦鹘鹔龃齿鳶龅鵑鵐龙鹠齅鷔鮻鯱鮺龃齿龅鱒鵟鱛龙黽鹵鹠齅鹘鹔鼌鼺龃龅鵟鳟龃齿龙鯔鯑鯸鰾鲃龮

Drupal\Core\Config\TypedConfigManager:: getFallbackName($name)

Schema 鵀鷡鮯鮮龅鳀鲾鷷鲺龮

麷鼌麽鸰龅鮪鮨鹵鸽鴗鼐鮧鮥鮡鳺龙龪鮯鮮 Schema 鵀鷡鵑鮞鹘鮚鮙齅鹩鮖齇龮

1 龮龪 Schema 鵀鷡龅鮑鮍鳩鮉鼌麽鲭鮇龙鰀鶗鵜鵀鷡龅鼌黹鴸鴷

2 龮龪鹘鹔鷲鷘鷔鮉鹔鮂鮀龅鲭鮇龙麷鵑鵐 label 魽鶠魺龙鹠齅魷鵶魳黓鲭鮇鰀鶗

3 龮麟鱛鱗鷘鷔鶟鯱龙鼞鴞鷔魬鯝鯱

4 label 鲍鷔鶟鯝鯱鳩鳨龙鳉鴗鲥麷鼌麽鶟魤黌黽鼫鮺

5 龮齼鷣鲏鴊 type 鲍鼞鴞鷘鷔鯝鯱龙魞鼞鵖麷魜鴯

6 龮鸨鳘魖齿魓鵡魏齾麏麟鱛鱗龙齔鼫鷘鷔鶟鯝鯱鳩鮉

7 龮鲭鲪鸂魋黛龙魈魇 yaml 鴯鸽魃鬿

黖鼇鹠齅鲜鳌鬽鬹鰀鶗鷲龅鮪鮨鬷鬵

鵙鹘鹔鸰鹥鸽鵀鷡麇龙龈鷶齛鸨鳊鲜鲛齦黀龅鬳龙黽麽麛齛 schema 鵟鳟鴋鶫鬯龓鴞鬬鹽龅鬨鳺鼼

Schema 鵟鳟鴋鶫鬯龓龮

鷔齅鲛鶌龈鷶鷲鵡鬤鷔龅鹥鹤鸜龞龝鸜鹰鹬鵟鳟龅鵟鳟 schema 鵀鷡

齝鬣 id config.storage. schema

龃龮 Drupal\Core\Config\ExtensionInstallStorage

齅龪鬤鷔龅鹥鹤鸜龞龝鸜鹰鹬鵟鳟鷲 config\schema 鴁鳽鲟鵊 yml 鵀鷡龅鷜鸽鲜鲛鵟鳟 schema 鵀鷡鼼

鹳鹱鷲鵀鬷鬵鹰鹬鸸鯊鹩麷鸨鹩 schema 鵀鷡鹴鱒鬢 schema 鵟鳟鴋鶫鬯龓龅 getAllFolders() 鷜鰾鬟鯔龙鵜鷜鰾鲥鬟鯔鵡鬤鷔鹥鹤龅 schema 鵀鷡龙鲏鳶麏鵀鷡鳶龙鲍麏鵀鷡鳱鳭鹓龮

Array
(
    [core.data_types.schema] => core/config/schema
    [core.entity.schema] => core/config/schema
    [core.extension.schema] => core/config/schema
    [core.menu.schema] => core/config/schema
    [automated_cron.schema] => core/modules/automated_cron/config/schema
    [block.schema] => core/modules/block/config/schema
    [block_content.schema] => core/modules/block_content/config/schema
    [ckeditor.schema] => core/modules/ckeditor/config/schema
    [color.schema] => core/modules/color/config/schema
    [comment.schema] => core/modules/comment/config/schema
    [comment.views.schema] => core/modules/comment/config/schema
    [contact.schema] => core/modules/contact/config/schema
    [contact.views.schema] => core/modules/contact/config/schema
    [contextual.views.schema] => core/modules/contextual/config/schema
    [datetime.schema] => core/modules/datetime/config/schema
    [dblog.schema] => core/modules/dblog/config/schema
    [dblog.views.schema] => core/modules/dblog/config/schema
    [editor.schema] => core/modules/editor/config/schema
    [field.schema] => core/modules/field/config/schema
    [field.views.schema] => core/modules/field/config/schema
    [field_ui.schema] => core/modules/field_ui/config/schema
    [file.schema] => core/modules/file/config/schema
    [file.views.schema] => core/modules/file/config/schema
    [filter.schema] => core/modules/filter/config/schema
    [history.views.schema] => core/modules/history/config/schema
    [image.data_types.schema] => core/modules/image/config/schema
    [image.schema] => core/modules/image/config/schema
    [language.schema] => core/modules/language/config/schema
    [link.schema] => core/modules/link/config/schema
    [locale.schema] => core/modules/locale/config/schema
    [menu_ui.schema] => core/modules/menu_ui/config/schema
    [node.schema] => core/modules/node/config/schema
    [node.views.schema] => core/modules/node/config/schema
    [options.schema] => core/modules/options/config/schema
    [path.schema] => core/modules/path/config/schema
    [rdf.data_types.schema] => core/modules/rdf/config/schema
    [rdf.schema] => core/modules/rdf/config/schema
    [search.schema] => core/modules/search/config/schema
    [search.views.schema] => core/modules/search/config/schema
    [shortcut.schema] => core/modules/shortcut/config/schema
    [system.schema] => core/modules/system/config/schema
    [taxonomy.schema] => core/modules/taxonomy/config/schema
    [taxonomy.views.schema] => core/modules/taxonomy/config/schema
    [text.schema] => core/modules/text/config/schema
    [tour.schema] => core/modules/tour/config/schema
    [update.schema] => core/modules/update/config/schema
    [user.schema] => core/modules/user/config/schema
    [user.views.schema] => core/modules/user/config/schema
    [views.access.schema] => core/modules/views/config/schema
    [views.area.schema] => core/modules/views/config/schema
    [views.argument.schema] => core/modules/views/config/schema
    [views.argument_default.schema] => core/modules/views/config/schema
    [views.argument_validator.schema] => core/modules/views/config/schema
    [views.cache.schema] => core/modules/views/config/schema
    [views.data_types.schema] => core/modules/views/config/schema
    [views.display.schema] => core/modules/views/config/schema
    [views.entity_reference.schema] => core/modules/views/config/schema
    [views.exposed_form.schema] => core/modules/views/config/schema
    [views.field.schema] => core/modules/views/config/schema
    [views.filter.schema] => core/modules/views/config/schema
    [views.pager.schema] => core/modules/views/config/schema
    [views.query.schema] => core/modules/views/config/schema
    [views.relationship.schema] => core/modules/views/config/schema
    [views.row.schema] => core/modules/views/config/schema
    [views.schema] => core/modules/views/config/schema
    [views.sort.schema] => core/modules/views/config/schema
    [views.style.schema] => core/modules/views/config/schema
    [bartik.schema] => core/themes/bartik/config/schema
    [seven.schema] => core/themes/seven/config/schema
)



龈鷶龪龣鱃黽黹



schema



鵀鷡鵑龙黊鷘鷔



yaml



鱟龇齾鬣龙鹳鹱鷘鷔鷣鷡鷬鷫龅鱟龇齾鬣龮



Drupal\Component\Serialization\Yaml

鲣龪鬑鯫鵟鳟鵀鷡鷲黌鹠齅鬎鵶鶘鹘 yaml 鱟龇齾鬣

鲏鳶麏龮 yaml_parser_class

鸨龮 $settings[' yaml_parser_class ']=鴑 鱶鱲鹘龃鳶 鴑;

鵜鬉鵖龪鴈鴆鷬鷫龅 Drupal\Core\Serialization\Yaml 鷲鷷黆龮 $class = Settings::get('yaml_parser_class')

 

鵟鳟鷞麤鬈鶫龮

龪鵟鳟鷞麤 Drupal\Core\Config\Config 鬅鷔鼓鬄龅 save 鷜鰾黛鸂鬈鶫鵑龙黊黛鸂齼齻鸡鸠鴊龃齿魏齾龙鬢鬂鸨鹩龮

髿龌鸡鸠鵟鳟鳶龙龐齐麷鯫鯱鸜鼞髻鬢 250 麟鱛龙鼞鮉 ?: * < > " ' / \ 鷘鷔鸨鹩鷜鰾

public static function validateName($name)

鵟鳟 schema 龅鸸鯊鹩龙鶊齻鵟鳟 schema 魏齾鵟鳟鲍龅龃齿龙鷘鷔鸨鹩鷜鰾龮

protected function castValue($key, $value)

鵤麷鵟鳟 schema 齇黛鸂黰龟龅鵟鳟鲍鸡鸠龙鲍麒鹠齅麏 null 鸜鬷鶇鹄齼鷣龙鷘鷔鸨鹩鷜鰾龮

protected function validateValue($key, $value)

髪龶龪鲀鳟鵟鳟鲍鵑龙鵟鳟齼鷣龅鲏鳶黌黊鵡鸡鸠龙鼞鵖鮉麷鯫鯱龙鷘鷔鸨鹩鷜鰾龮

protected function validateKeys(array $data)

齅齕鬢鬂龅 castValue 鷜鰾齛鳙鵟鳟齼鷣鷲龅鬷鶇齼齻鹄 NULL 鱂齻鵟鳟 schema 鷲龅鲀鹘魏齾麏鷞鵕龅 php 黰龟齼齻龃齿龙黌麛齛髦鸂鹒 Drupal\Core\TypedData\PrimitiveInterface 鷲龅 getCastedValue() 鷜鰾龙黽鹵鵟鳟鴸鴷齼鷣髢鬢龃齿髡髟麇鶂鱟龇齾鬈鶫鶌齼齻髝 config 鵪鷲龙鵜鵪鷲鬈鶫龅鵟鳟鴸鴷齼鷣麒鳩鮉鬷鶇齼齻龃齿鼼

鹠齛龈鷶齛鸨鳊髜鵟鳟鷞麤鴊龃齿齾齼齻鷣鷡鴼鶍髙鶤鵕鷔龅鬳髖黽麛齛龃齿齾鵟鳟髕齃鬣龅鬨鳺鼼

龃齿齾鵟鳟髕齃鬣龮

鶊齻鵟鳟 schema 鹘鹔鳙鵟鳟鷞麤鷲龅鵟鳟齼鷣魏齾麏龃齿齾齼齻鷞麤龙黽鹵麛鹠齅齅龃齿齾齼齻鷞麤鶤鰠鳺鵟鳟齼齻鹒龙鵜鬯龓鹘鹔鸨鹩龮

 config.typed:
    class: Drupal\Core\Config\TypedConfigManager
    arguments: ['@config.storage', '@config.storage.schema', '@cache.discovery', '@module_handler']
    tags:
      - { name: plugin_manager_cache_clear }

龪鷷黆齕龙鵜鬯龓鷷髈齛鼌麽髆鷡髕齃鬣鹴鲃龟龈龇龅髆鷡龞龝髅鹓龙鹜髂鼓龃齿齾齼齻髕齃鬣龙鳙鵟鳟 schema 鹘鹔鵙鮺髆鷡鳌髀龙鳛鼌麽 Schema 鹘鹔鶮齛鼌麽髆鷡龃齿龙龃齿鳶麛齛髆鷡 ID 龙鳛鼌麽 Schema 鵀鷡鶮鱒鬢髆鷡骽鲨鲛鶌龙 schema 鹘鹔麛齛髆鷡鹘鹔龙鴊鱎鴫髆鷡髕齃鬣鼞麰龅齛鶰齰鼞齅鮇鵀鳺麏髆鷡黈黆骽鲨龙黾齛齅 Schema 鵟鳟鴋鶫鬯龓鳺麏黈黆骽鲨龙鹘鹔龅黈黆龃麏龮

Drupal\Core\Config\Schema\ ConfigSchemaDiscovery

鵜髆鷡髕齃鬣鷲 $this->getDefinitions() 鱃鰐龅髆鷡鹘鹔齼齻麏鼌麽齼鷣龙鲏鳶麏鵟鳟龃齿鳶龙鲍麏鷞鵕龅 schema 鹘鹔齼鷣龙骼鶫龪齼齻髝鵪 cache_discovery cid typed_config_definitions 骻鴁龅 data 麟鯮麝龙鹩骺麇鷘鷔鹩龇鬂鱟鲜鳌龮

$a=file_get_contents("cache_discovery-typed_config_definitions.bin");
$a=unserialize($a);
print_r(array_keys($a));
print_r($a);

龪龈鷶鷲鵀鹳鹱鹰鹬鸸鯊鹩龙鹘鹔鹒鹦鼋鼇鼟鵟鳟鷞麤齼齻龃齿龙黌鹠齅鷘鷔鸨鹩鷜鸽鲜鳌龮

鲜鳌鵤麷髢鬢鹥鹤骶黫鸬齃龅鹘鹔龙黌麛齛骴鹥鸽鵀鷡鷲龣鱃龅鹘鹔龙龪骰鲨鬣鷲髦鸂龮

        $discovery = new \Drupal\Core\Config\Schema\ConfigSchemaDiscovery(\Drupal::service("config.storage.schema"));
        print_r($discovery->getDefinitions());
        exit();

鲜鳌髢鬢鹥鹤骶黫鸬齃鬢龅鹘鹔龙龪骰鲨鬣鷲髦鸂龮

$c=\Drupal::service("config.typed");
$a=$c->getDefinitions();
print_r(array_keys($a));
print_r($a);
exit();

鵜龃齿齾鵟鳟髕齃鬣龅龞鴞鷜鰾鬉鵖鸨鹩龮

public function getDefinition ($base_plugin_id, $exception_on_invalid = TRUE)

鱒鬢龃齿鳶鹴黌麛齛髆鷡 id 鹓鰐鶌鰿麲鶍齰麇龅龃齿鹘鹔齼鷣龙龃齿鳶骭髢鬢鯔鯑鸬齃龙鲣齼鷣鷲齣齢龅鸤鯺龃齿鷲龅鯳鶇骩鵨黛鸂骨骤龙鸨鳘龃齿鼞鶫龪龙齇鬟鯔 undefined 龅鹘鹔

public function buildDataDefinition(array $definition, $value, $name = NULL, $parent = NULL)

鱂齻 getDefinition 鷜鰾鬟鯔龅鴼鳘龙骢齘龃齿齾齼齻鷣鷡鷧鴞龅齼齻鹘鹔龃龙麷鷩鹘鹔龃鷞麤麛鹠齅骢齘龃齿龃齼齻鷞麤鹒龙鲘麏龃齿鹘鹔鷲鹠齅鮉麷鸤鯺龃齿龙齖鲍鹠鵖鱂鰅鼐鵟鳟齼齻龙麺齅鶰鷧鴞鳙鵟鳟齼齻鼌齰骠齭鼼

public function get($name)

鰖鳐鶊齻鵟鳟鷞麤鳶鬟鯔龃齿齾齼齻鷞麤龙鵜鷜鰾龅鷷黆鴊鵟鳟鷞麤鷲鰐鶌 schemaWrapper 鴹鶓 龅鷜鰾鼌鹵龙麺鼞麰龅齛鵟鳟鷞麤鷲龅 schemaWrapper 鴹鶓鳙鳩鮉鷷鵑鵟鳟齼齻鼼

鲭鲪龮龪鹳鹱鸸鯊鹩鹴骴齝鬣鷲鱄鱃鬯龓龅鸸鯊鹩鹓龃齿齾鵟鳟髕齃鬣鵤麷鲭齭鮞骘髕齃鬣龙齦鲥齛鶊齻 schema 鴸鴷魏齾鵟鳟龃齿龙鸨麷鷧骔鹠齅骐鸤鲭齭鼼

鵜髕齃鬣黊髦鸂 config_ schema _info 骶黫齅骍黋鹥鹤验骉龃齿 schema 鹘鹔齼齻龙黌麛齛髦鸂鹥鹤鹘鹔龅 hook_ config_schema_info _alter() 骶黫骇齼龙鵜鰠鳺鼞骍黋魳黓鹄鹃骅鵹 schema 鹘鹔鰎龙鲣鹠齅验骉

鬽鬹鰀鶗龮

鼌鸜 drupal 龅鵟鳟 schema 骁鶌鹒 Kwalify 鰎鴁 龅鬤黈龙鵜鰎鴁驾驽龮 http://www.kuwata-lab.com/kwalify/ yaml json 鷞鼐鴼鶄齾齼齻鶤鰀鸺鶠鶟龙黣龃鹠龣鶓鴊鹠齃齀鶓鸺鸰龙鲣鴊 xml 鱞鸵驷驴 DTD 黽鹵龅麯麫龙鵤麷鹥鸽龙鲘鷩 Kwalify 鰎鴁鳦黆鹒龙麏齀驰鵜驯龝黾麣龙齦齛鼌麽 yaml json 鴯鸽龅齀马鸜 schema 鸡鸠鸜齼齻驪鹘鬨驦鼼

驥鸜 鵟鳟 schema 驤驾鵀驡鼞鲣驟鳦鹒齀鮇鹡驟鳦鹒鼌黹鬨驦龙驛驽麏 https://www.drupal.org/node/1905070

鵸鸜 鵟鳟鵀鷡鮪鮨鬷鬵龙驤鷜驛驽龮

https://www.drupal.org/docs/develop/coding-standards/configuration-file-coding-standards

龟髅驔鵑麛驑鶌黽麝龙鹩鼌髅鳙鹜鹙驑齀鵟鳟龈鷶鷲龃齿齾龅鯹鷔

本书共71小节:

评论 (写第一个评论)