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

龭髻骇鵞麨骅鶠鼋麪龧鹶鼙髻鳜鹥鹡骅齄鵯鳢龜鸂鸀龕龔龑龙鰐鷟

本书共88小节:

评论 (写第一个评论)