77. 主题管理器themeManager

龹龷龳龰龭龹龩龧龤龡龠龤龜龙龘龹龷龕龓龏龹龷龕龓龎龡龹龷龋龊龕龓龆龂齿 D9 齸齷齵齴龂齱齯龓齬齫齧齣齠齞齚齖齒齎齌齊齇齄龹龷齃齀龋龊鼾龆齿鼽鼺鼶鼵鼱龆鼮鼬鼨鼤鼽鼺鼶鼢鼞鼛鼚鼖鼓鼐鼎

龹龷鼊龰龭鼎

鼉鼈 id theme_handler

黮鼎 Drupal\Core\Extension\ThemeHandler

黓龹龷龳龰龭黒黏齚黌黋龆黊黈黇黅黁龎麽龆麺龡麶麴麲鼛龆龤麰麯麫龹龷麪麨鼛麥麤齊麢麟鼾

龹龷麝麙麕鼎

鼉鼈 id theme.negotiator

黮鼎 Drupal\Core\Theme\ThemeNegotiator

龤麰麋麈鼢麇麆龤麂黏鹿龹龷龧齣鹻鼱鹺鹹鼛鹸鹷龹龷

龹龷鹴鹱齧龭鼎

鼉鼈 id theme.initialization

黮鼎 Drupal\Core\Theme\ThemeInitialization

鹨鹧龹龷鹤鹢鹟鹞齊鹛麈鹚鹗鹖鹒鼾

龹龷龋龊鹑鹍鼎

鼉鼈 id theme.registry

黮鼎 Drupal\Core\Theme\Registry

龳龰鹑鹍龹龷龋龊龆龡龹龷鼢麇齸鹃鸿鼛黏鹿龊鼢麇

鼈鸼鸸鼚鸶鸳鸱鼽鼺黅鼶鼢鼞鸯鼬鼓鼐龆鸮鸪鸨鸧鸥鸡鼮鸝黇龰鹛龎鸚龆鸗鸔鼽鼺黅鸒鸏鸎鸝鼚鹚鸊鸒鸆

龹龷龳龰龭鼎

鼉鼈 id theme.manager

黮鼎 Drupal\Core\Theme\ThemeManager

鷾鷼鷹鷶鼎 \Drupal::theme();

龹龷龳龰龭鷬龤鷩鷧鷥龹龷齃齀龋龊龆鷤龤鷩齱齯龹龷齎齌龆鷢鼖鸆

龹龷齃齀龋龊鷧鷥鼎

鷞鷚鸝鼚鷗鷖鼚鼖鷔鷑鷧鷥龜鷍鼛龓鷊齃齀龋龊鼎

\Drupal::moduleHandler()->alter($type, &$data, &$context1 = NULL, &$context2 = NULL);

黊龡麺黒龧龤麰龜鷍龆龹龷鶮鶬鼛齃齀龋龊鶩龩鸗鼖龠龤鼎

\Drupal::theme()->alter($type, &$data, &$context1 = NULL, &$context2 = NULL)

鶥黒龠龤鹻鼱鹺鹹鶤龤鼛龹龷龏鶡鶞鶛鶚鸨鶖龹龷齴鶮鶬鼛齃齀龋龊龆鸗鸔鶩龩鷧鷥鶔黏鹿鶐鶮龹龷鼛齃齀龋龊龆鶍鶌鶩龩鶉齄鸗鼖龠龤鼎

\Drupal::theme()->alterForTheme(ActiveTheme $theme, $type, &$data, &$context1 = NULL, &$context2 = NULL);

鵽鵹鸶鼱黏鹿龕龓鼛鵶龧龡鵳鷧鼨龕龓齇齄鼛龆鵯龓鸗鼖鼎

$theme 鼎鷢鼶鼢鼞龹龷鹴鹱齧鼵龆 ActiveTheme 鸯鵫龆鷔鵨龩齇齄齃齀龋鼛龹龷麪麨龏鶡鶞鶚鸨鶖龹龷齴

$type 鼎齃齀龋龊鵧龆鸝鼚龡黏鹿齚齖齒龆鷤鸝鼚龡鵦鵤鹿龋龊鵧齬鵣鼛龓齬龆鵠鵜麺鷚黁鵙鵗鷧鷥

$data 鼎鶩龩齃齀鼛龓鷊龆龋龊鶩龩鼚鵓龤鷹鵏鵌鵉

$context 鼎鵈齞鵅鹿鵯龓龡鵄鵁鵀齃齀龋龊鼛鴾鴻鸝鴺鵯龓龆鸨鸧鴶鴳鴲龤鴮

龹龷齃齀龋龊鼛龕龓鵧鴬鸪齣鼎

龹龷鴪龭鵧 _ 龋龊鵧 _alter

鴩鴨龹龷鴪龭鵧齣鴧 yunke 鴢龆龋龊鵧齣鴧 form 鴢龆鶍鶌龕龓齣鼎

yunke_form_alter(&$data, &$context1, &$context2);

齃齀龋龊黏鴞鼬鼨鴚鴖齿龹龷鼛龹麪麨鹟鹞齸龆龹麪麨鹟鹞齿龹龷鹴鹱齧鵜鵗鴓鹷鹨鹧龆鸗鸔鴚齿鶛鴏鹟鹞齸龆鶩龩鴓齄鼊龰鹟鹞鹨鹧鴌龷

龹龷龡鸨鹚鹗鼛龆鷧鷥齃齀龋龊鵜龆齿鹚鹗鴈齸鼬鼨龡鴄龹龷鼤齇齄龆鴂鵈齇齄鹸鹷龹龷龆黊鴁龎鳿鼛龡鳻鼱鼛鵽鳹龏 drupal8.5 齴鸨 bug 龆鳳鳰鳭鳪麯鳩鸒鳧鳣龆鶚鼚鹺鹑鳡鸳鸱鴌龷龆鳻鼱鸨 bug 鼛鵽鳹龡鼤齇齄鳝鵌鶖龹龷龆鳛鵈鳗鳖鴮鴄龹龷龆鴂鵈齇齄鹸鹷龹龷鸆

鸗鸔鵄鵁鼛齃齀龋龊鵧龡龓齬龆鶍鶌齿鹚鹗鴈齸龆麺鷚龂齿黏鹿龹龷齸黁鵙齇齄黅鵈龆齿齇齄鼖黏鹿龹龷

齱齯龹龷齎齌鼎

龹龷龳龰龭鷤鵗齱齯龭龏 \Drupal\Core\Render\Renderer 齴龤鷩齱齯鴨鴖鸒 #theme #theme_wrappers 鳎鳍 鼛齱齯龓齬龏鷢鼶鼢鼞齱齯龭鹤鹢鼓鼐齴龆鴩鴨 $elements 龡黏鹿齱齯龓齬龆鶍鶌鸗鸔鴨鴖鸒 $elements['#theme'] 鳂鳁鸨鴨鴖 $elements['#render_children'] 鶍鶌鲿鴲鲼鹷龹龷龳龰龭鶉齄齱齯龆龠龤鸗鼖鼎

$elements['#children'] = \Drupal::theme()->render($elements['#theme'], $elements);

齱齯鲺鸔鲸鲷齿齱齯龓齬鼛 '#children' 鳎鳍齸龆龹龷龳龰龭鲶鵙鴨鴖 $elements['#render_children'] true 鼚鲲鲯鵤鳖齱齯鲭鵣鲫鲨鵁鲦

龡鸮鵽鳹鸒龹龷龋龊齵麋鲥齱齯龓齬鼛 #theme #theme_wrappers 鳎鳍龡鸮鲷齿鴻龆鲤龩鲡黇鸮鲠鼛鲟鴮龹龷龋龊龆鳂鲛鲘鲶鲕龎齣 false 龆鸗鸔鵽鳹鸒龹龷龋龊龆鶍鶌龹龷龳龰龭鸼鲒齱齯鶚鸨龊鲑鲏龆鵠鵜齱齯龭龎鴲鲎鹨 $elements['#markup'] 鼛鲶鲕齿齎齌鼱齞龆鷤龎鴲鲎鹨 #prefix #suffix 龆鶥鸧鲎鹨鲍龧龡龹龷龋龊鼛鲋鲈鸆

齱齯鲄鲀鼎

龠龤鱼鱺鼎

\Drupal::theme()->render($hook, $elements);

鶛齸 $hook 鸝鼚龡鱸鹿龹龷龋龊龆鷤鸝鼚龡黏鹿龹龷龋龊鱴鵣鼛龓齬龆鸗鸔龡龓齬鼛鱰龂鱬鱨黏鹿鴮鴂鵈黏鹿鳗鳖鱥鲟龆鶤龤鱨黏鹿鸨鱢鼛龋龊龆鵦鵠鱞鱜鶮齌黏鹿鵄鱼鼛鱚鹱龋龊龏龓齬鲟黅鷤鳁鸨鸨鱢鵽鳹鵜龆鶍鶌麆龤鴂鵈黏鹿鲑鲏鱖龧齣鱚鹱龋龊齴鸆

鸗鸔鱚鹱龋龊鳁鸨鵗鵽鳹龆鶍鶌鱥鲡麺龡鸮鶡鶞鱒鼖鱑鱍鴧 __ 鴢龆鸗鸔鶡鶞龆鶍鶌鱌鱊龋龊龡麪麨龋龆鶍鶌鱇鱃鴄鷹鱃鱁鱀鱥鲟龆鶤龤鱨黏鹿鲟鴮鼛龋龊鰽鸗鸔鳗鳛鳁鸨鵽鳹鼛龋龊龆鶍鶌鲛鲘 false 龆齱齯鲺鰼鰺齿鰹龓齬鼛鴶鴳鼖鰵鰲鰱鰰鸆鸗鸔鲟鴮龆鶍鶌鵦鵠鱜鶮齌黏鹿龹龷鵽鳹鼛鹴鹱龋龊龏鹴鹱龋黓鱚鹱龋鰬鰪鼎鹴鹱龋鹤鰩鸝黇龡麶鸶黏鱀鼛龋龊龆麺鸼鲒鳪鷖鹑鹍龆鰦鱚鹱龋龎龩鹹黏鶮龡鹑鹍鷖鼛龆鶥鵅鹿鸥鸡齿鼖鹟鵤鳖龤鴮龆鹑鳡鰬鰪齴鸆

鰢鴮鹴鹱龋龊鵈龆鱜鶮鰡鰠龓齬龏龤麰鵄鵁鵀龜龙龘龹龷龕龓齴龆齱齯龓齬齸鸗鸔鸨龋龊鶮鶬齸鼛鰡鰠龆鸪龂鱖麯鷼齌鷩鰟鰞龋龊鶮鶬鼛鰜鰘鱖龆鸮鸪麆龤鰜鰘鱖龆麽鵜龂鱚鹱龋龏鹑鳡龎龡鹴鹱龋齴鼚 'theme_hook_original' 龧齣鰔鵧鲸鲷鴮鰡鰠龓齬齸龆鹑鳡鸗鸔齱齯龓齬齸鸨龋龊鶮鶬齸鳁鸨鶮鶬鼛鰡鰠龆鰑鷚龎鴲鵗鵄鵁龆鰏鰍鱰鱌龜龙龘龹龷龕龓黒鵌鵉龋龊鶮鶬齸鰉鱊鼛鰡鰠鼚鰆鰅鼊龰龕龓鰄鹨鼛鰡鰠鸆

鱜鶮鶖鼶龋龆鷤鲿龡龋龊鶮鶬齸鼛 'base hook' 鱖龆鸗鸔鳁鸨鼨鱖龆鱌鱊鹴鹱龋鼶鰃鲿龡鶖鼶龋龆鼚鶖鼶龋鶉齄龹龷龋龊鰀鯾龆鳪鷖龹龷龋龊鰀鯾鵈龏鷢鼖齴龆鰢鴮鲠鯺龩鶤龤鼛龋龊鶮鶬鸆

鴄鷊龋龊鶮鶬鹨鹧鹤鹢鹟鹞龆鰺齇齄鰅鼊龰龕龓鼎

preprocessor_function(&$variables, $hook, $info);

鰅鼊龰龕龓鼬鼨鼚鵓龤鷹鵏鵌鵉鰡鰠龆鼚鯸鶉齄齃齀龆鼢麇鯵鯴鶛鲛鲘鱖龆鱨鯳鹿鵯龓龡鹴鹱龋鵧龏龎龡鱚鹱龋齴龆 $info 龡龋龊鰀鯾鵈鼛鶮鶬龏龎黏鶮龡鹴鹱龋鼛鶮鶬齴

鯰鯮鰅鼊龰龕龓鰄鹨鸝鯫鯧鲑龓鷊鴮齱齯龓齬龏鷗鷖齿鰡鰠齸鴨鴖 '#attached', '#cache' 鷹鵏 鯣鹨齴龆鶥鸝鼚鯠齱齯鸶鼖鹟鸯鵫鯟鯜鴮鰅鼊龰龕龓鴾鴻鯣鹨鼛鰄鹞黓鯛鲷鳎鳍龆黊鯛鲷鳎鳍齸龎鯰鯮鯛鲷 'keys' 龆鸨鷤鴲鵗鯘齵龏龎鴲鯗齌鯔鯐齴

鸗鸔龹龷龋龊鶮鶬麆龤龹龷龕龓龆鶍鶌齇齄麺鯍鯊齎齌龆鲛鲘 Markup 鸯鵫龆齱齯鲺鰼龆鸮鸪鶉齄鼚鼖龜龙齱齯鹖鹒鸆

鸗鸔麆龤龜龙鷹鵏龆鶍鶌鴄鷊麆龤鼛龜龙鵓鯉鱜鶮齱齯龕龓鰆龜龙麪麨鸆鰜鰘鶤龤鼛龡 twig 龆麪麨齣鴧 .html.twig 鴢龆麺鼛齱齯龕龓龡鯆麰 core/themes/engines/twig/twig.engine 鹟鹞齸鼛鼚鼖龕龓鼎

twig_render_template($template_file, array $variables)

齿龜龙鵽鳹齸鱜鲸鯁齄鸒鼚鼖龕龓龏鼨龕龓龹龩龤麰鯣鹨鷗龤龜龙鰡鰠龆鯀鮿鷢鼖鹟齴鼎

template_preprocess($default_template_variables, $hook, $info);

齿龹龷龋龊鹑鹍鷖鲀齸龆鸨鸧鶐鮼鴶鴳鼖鼨鰅鼊龰龕龓鸝黇鳁鸨鵗鵉鮹鴮龆鰩鸗龋龊鱚鹱鵽鳹齣龹龷龕龓鷹鵏龆鵈鮵鵗鰟鰞齣龜龙鷹鵏龆鶍鶌龂鮲鮱鸆

龏鼨鼊鵽鳹齣鮰鶌龎麋鲥鼨龕龓龡鸮齿 $info['preprocess functions'] 齸鮭鮬鶛鵽鷤龡鸝鼚鼛龆黊鷗鷖 'directory' 鮩麋鲥鲸鮦龜龙鮥龡鸨鼨鰡鰠龆鳍黇鮢鮡鷤鮠齴

鼊龰鳎鳍鶡鼎 'attributes', 'title_attributes', 'content_attributes' 龆鸗鸔齱齯龓齬龘龋龊鶮鶬齸鲷齿鴏鷚龆鸨鱖鵜龂鶡麟鴮鳎鳍鶡龆鲫鱖鵜鮜鱖齣鮙鳎鳍鶡

theme_hook_suggestions 龧齣鰡鰠鵧鰄鹨龋龊鰀鯾龓齬龏齿龜龙齱齯龕龓齸鸝龤麰龠鮕鳻鼛齴

theme_hook_suggestion 龧齣鰡鰠鵧鰄鹨鹴鹱龋龊鵧龏龎龡鱚鹱龋龊齴

龠龤齱齯龕龓 $render_function($template_file, $variables); 龆鰜鰘鼛 twig 齣龏鼱鹟鳭麯鴮齴鼎

twig_render_template

龹龷龋龊鰀鯾鼎

龹龷龋龊鰀鯾龕龓龏龘鸝鮔鮐龹龷龋龊鰀鯾龋龊龆鵈麇鮏齣鰀鯾龕龓齴龡鴄鷊鶖鼶龋龏 base hook 齴鮋鵧鼛龕龓龆麺鵀齌鶖鼶龋龊鸝鶤龤鼛鶚鸨麪麨龋龊龆鶥鮏齣鴧鰀鯾鴢龆鼚龓齬鲛鲘龆鼨龕龓黒鵦龜鷍鶮鶬龏龹龷鸝鶮鶬鰀鯾齃齀龋龊龆鷢鼖齴龆鮈龜鷍鼛鰀鯾龕龓鲛鲘鲺鸔鵗鮆鰺龆鶮鶬鶖鼶龋鼛龜鷍鷗鯐鼬鼨齣鶛鶮鶬鰜鰘鼛鰀鯾龕龓龆鼚鯸鶤龤麶齣鮆鮅鼛龜龙鰽鶮鶬鰆鮋鵧鸗鼖鼎

hook_theme_suggestions_HOOK($variables)

鷤鲿龡鼎龜鷍鴪龭鵧 _theme_suggestions_ 鶖鼶龋龊鵧 ($variables)

麺鵌鵉鰡鰠龓齬龧齣鵯龓鱖龏鸝鵓龤鷹鵏齴龆鶛齸龋龊鵧黒鸝鶤龤鶖鼶龋龆龎鸝鶤龤麪麨龋龏鰬鰪鷢鼶鼢鼞龹龷龋龊鹑鹍齴鰽鰀鯾齸鼬鼨鶡鶞鶖鼶龋龆鹴鹱龋鮥鵗鴓鹷鹨鱼龆鱚鹱龋鸝鼚鱬 $variables['theme_hook_original'] 齸鷾鷼

鼢麇黒齣魼魹鼛龋龊鵽鳹鰀鯾龕龓龆龎鲷齿魵鸯鶚鸨龋龊鵽鳹鼛鰀鯾龕龓龆鷤鲿龡鱌鸗鼖鼛龕龓龎鲷齿鼎

龜鷍鴪龭鵧 _theme_suggestions

鰀鯾龕龓鲛鲘鼛鰀鯾龓齬龎鶩龩鹢魱魭鼤鸳鸱龆魫齣鵠魩魦鸝鵦鵤鹿龜鷍黏魥鵯魤龆鲫鷶鲸鮦魣魹鼛鸳鸱龆鸳鸱鼛龠魣鼬鼨齿鰀鯾齃齀龋龊齸鶉齄龆鷢鼖鸆

鹻鵉鮹黅鶚鸨鼛龋龊鰀鯾鵈鼢麇鷧鷥齃齀龋龆鸝鴺鼛齿齃齀龋齸鯣鹨龘鯘齵龋龊鰀鯾龆黊鸼鲒齿齃齀龋齸鵽鳹魡鸱龆鰀鯾龓齬鵈齞鼛鲑鲏鰩鼱齞鼛鲑鲏魭鼤鱀麶魠龆鸗鸔鼮龡黏鯆龜鷍鮢鷥麕龆鶮鶬鸒鶖鼶龋龆鼬鼨齿鵽鳹鰀鯾龕龓鼛麽鵜鵽鳹齃齀龕龓龏齃齀龋龊齴龆龤齃齀龕龓鲸鮦龋龊鸳鸱鸆

龜鷍龘龹龷鸝鵽鳹魵鸯鶚鸨龹龷龋龊鼛齃齀龋龆鷤鸝鵽鳹魵鸯鶔魼魹龋龊鼛龆鵽鳹鸗鼖鼎

hook_theme_suggestions_alter(&$suggestions, $variables, $base_hook)

鷗龤齃齀龋龆魵鸯黁鵙龹龷龋龊齃齀鰀鯾

hook_theme_suggestions_HOOK_alter(&$suggestions, $variables, $base_hook)

魼魹齃齀龋龆魵鸯魼魹龹龷龋龊齃齀鰀鯾

齇齄鸳鸱龡龜鷍齊鶖龹龷鳛鵈龡鹸鹷龹龷龆鵈齞鼛鸝鼚鰟鰞鼱齞鼛龆鶚鼚鹸鹷龹龷魭鼤鱀鴂魠龆齿麽黏鹿龜鷍龘龹龷齸龆鷗龤齃齀龋鼤齇齄龆魫鵠魼魹齃齀龋鸝鼚鶉齄鰟鰞龆鵈麕魭鼤鱀麶魠

齃齀龋魟鼬鼨鼚鵓龤鷹鵏鵌鵉鲷齿鼛鰀鯾龓齬龆鹻鼊龰黅鵣鵈龆鼢麇鰘齣鰀鯾龓齬齸魝魚鵈鼛龋龊魭鼤鱀魝魠龆鱨黏鹿鲑鲏鴂魖龆魫鵠鱬鴂鵈黏鹿鮢鹱鱥鲟龆鼚鲟鴮鼛鱨黏鹿鵗鹑鹍鼛龋龊齣魕鶉齄龹龷鵽鳹鸆

鰹鯐魔龩鼛魒鹿龹龷龋龊鰀鯾龕龓鼎

鼐魏龜鷍鼛龹龷龋龊鰀鯾龕龓鼎

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function node_theme_suggestions_node(array $variables) {
  $suggestions = [];
  $node = $variables['elements']['#node'];
  $sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');

  $suggestions[] = 'node__' . $sanitized_view_mode;
  $suggestions[] = 'node__' . $node->bundle();
  $suggestions[] = 'node__' . $node->bundle() . '__' . $sanitized_view_mode;
  $suggestions[] = 'node__' . $node->id();
  $suggestions[] = 'node__' . $node->id() . '__' . $sanitized_view_mode;

  return $suggestions;
}

魣齠齞龋龊鰀鯾鼎

C:\root\drupal\core\includes\theme.inc 齸鼛 theme_get_suggestions 龕龓

龊鲑鲏齱齯鼎

龘鯮鼮鳭鳪鹑鳡鴮鸒鵄鵁鵀龜龙鼛鰡鰠龘麕鰅鼊龰龕龓鼊龰鼛鰡鰠魟鲤龡齱齯龓齬龆鰦鴏鷚齿龜龙齸鼚鳝鵌齎齌鼛鷹鵏齎齌鸒龆鶥龡魆鶌鲘魄鮭鮬龜龙齸龤麰鳝鵌齎齌鼛鰡鰠龎鼬鼨龡魀鰠黮鬿鶌鮬齿鱚鯊 twig 齸鱜鵽鸗鵠龆 drupal 鬽黇鶥鬻鼊龰龡魫齣麺齣 twig 鯣鹨鸒麪麨龆鹻龜龙齸鳝鵌鬹鬷黏鹿龓齬鵜龆龂鵗鹻鮐齱齯龓齬龆鱇鳖龠龤 drupal 齱齯龭龆鹢麰鶥黏魏鹺鷢鼶鼢鼞鵈鸊鼛 twig 鼉鼈鹤鹢龹龷龆齣鸒鬴鹸鸝鬱鲍龧龆齎齌鲶鲕齿鼢麇齸鮥龡鬭鰠鲸鬩齱齯龓齬鷹鵏鼛龆龊鲑鲏鼛齱齯鲘鬨鬤鬡鴮鸒龜龙鵓鯉鲶鵙鸆

鰅鼊龰龕龓鰄鹨 attached 黓鯛鲷鼊龰鼎

鰅鼊龰龕龓鸝鼚鱃鵄鵁鵀龹龷龕龓龘龜龙鼛鰡鰠齸鯣鹨鴾鴻鼛鰡鰠龓鷊龆魫鵠鶥鸧龓鷊鼛鯛鲷鳎鳍鷤鼬鼨鬠鬜鴮齱齯鲺鸔鼛鯛鲷鳍龆鵠鴻鲤鸨鰄鹨鬚鬘鴌龷龆鰅鼊龰龕龓鸝鼚齿鰡鰠龓齬齸鴨鴖 '#attached', '#cache' 鰔鵧鼛鷹鵏鹛麈龆鸝龂 '#attached', '#cache' 鬕齣黓齿齱齯龓齬齸黏鬻龆齿齱齯鲄鲀齸龆鴏鷚鴲鵗鮆鰺鴮齱齯鸶鼖鹟鬓鬒齸龆鬐鴮黓齿齱齯龓齬齸鬎鶮黏鬻鼛鱢鸔鸆

鮢鷥麕鶩龩鶐鰪鹑鳡鼨鴌龷龆鵄鵁鸒鴾鴻龓鷊鷤鶩龩鵄鵁麺鷚鸆

template_preprocess 鰅鼊龰龕龓鼎

鼨鰅鼊龰龕龓鯆麰鼎 core/includes/theme.inc 龆龧龤龡齣鶚鸨鼛龜龙鰄鹨鷗龤鰡鰠龏龹龷龕龓鷹鵏鰜鰘龎鹨齴龆鷗龤鼛龜龙鰡鰠鸗鼖鼎

[
    'attributes' => [],
    'title_attributes' => [],
    'content_attributes' => [],
    'title_prefix' => [],
    'title_suffix' => [],
    'db_is_active' => !defined('MAINTENANCE_MODE'),
    'is_admin' => FALSE,
    'logged_in' => FALSE,
    'directory' = \Drupal::theme()->getActiveTheme()->getPath();
  ]

龜鷍鸝鼚鵽鳹 template_preprocess_default_variables 齃齀龋龊鮩齃齀鯣鹨鰜鰘龜龙鰡鰠龆鸗龤鬉龜鷍鼎

user_template_preprocess_default_variables_alter(&$variables)

齿黏鹿鹺鹹齸鶚鸨龜龙鼛鰜鰘鰡鰠鵗鯛鲷齿齸鬈鬄鬁龕龓 drupal_static(__FUNCTION__) 齸龆魫鵠鮢鷥麕鷤鸝鼚鷗鷖鸗鼖鷹鵏鮩齀鰡鰜鰘鱖鼎

$default_variables= &drupal_static(鴧template_preprocess鴢);

鸗鸔鵄鵁鵀龜龙鼛鰡鰠鳭鳪鸨鶔鹿鱖龆鶍鶌魭鼤鱀魠麰鰜鰘鱖鰽鸗鸔鴨鴖鸒鰡鰠 'attributes' 龆鶍鶌麺龂黓鰜鰘鱖鮆鰺鸆

鹑鳡鼎齿鼨龕龓鼛鹑髿齸麯鴮鰑龡鰅鼊龰魩魦齇齄鼛鱨黏鹿龕龓龆鶥龡龎鯺鱜鼛龆髻鳛鸿鵤龓鴶鴳龡鸗鵠黊鸨髷鴻龆鰅鼊龰龕龓龎龩鳗髳齇齄鸳鸱



contextual_preprocess



鰅鼊龰龕龓鼎

齿鼢麇鰜鰘麢麟鵜龆魵鸯鶚鸨龹龷龋龊鼛鷗龤鰅鼊龰龕龓黒鸨鵅鹿龆齵鸶鹟髯鴮鼛 template_preprocess 鴻龆鲿龡鼨龕龓鸒龆龤麰鼊龰鸶鼖鹟髫鵌龆鯆麰鼎

\core\modules\contextual\contextual.module

鼮鸝鼚鴓齄鲡鲡

鳎鳍鼊龰鼎

齿鵄鵁鵀龜龙鼛鰡鰠龓齬齸龆鰔鵧 'attributes', 'title_attributes', 'content_attributes' 鸨鶐鶮鶞鶬龆鵨髧鳎鳍龆鴲鴓鹷鵗鼢麇鶡麟鴮鳎鳍鸯鵫齸龆鶥鸧鰔鵧龎黇龤龧鴏龤

鵓鯉齱齯龕龓鼎

鵓鯉齱齯龕龓龡龹龷鼢麇龠龤龜龙鵓鯉鼛鱼鱺龆鮋鵧鴬鸪鼎

鵓鯉鵧 _render_template

麺鵌鵉龜龙鹟鹞鬨髦龏鱬鼢麇鴄鳻鰲鮢鹱鼛鬨髦龆鶡鶞鹟鹞鵧鰆麪麨鵧齴龆鼚鰆龜龙鰡鰠龆鰜鰘鼛 twig 鵓鯉龕龓鸗鼖鼎

twig_render_template($template_file, array $variables)

鯆麰鼎 core/themes/engines/twig/twig.engine



龠鮕髢髠鲿齿鼨龕龓齸鯣鹨鼛龆鹑鳡鼎



THEME HOOK: 鼛鱖龡鱚鹱龋龊龆龎龡鹴鹱龋龊

FILE NAME SUGGESTIONS: 鼛鱖齸鱨黏鹿魭鼤鱀鴂魠龆鹻鼱鵗鴺龤鼛龜龙鼚 'x' 鮢髜龆鸮鸪鼚 '*' 鮢髜

BEGIN OUTPUT from 鼚鰆 END OUTPUT from 鱖鹤麽龆龜龙黁鬨髦龆鱬鼢麇鴄鳻鰲鮢鹱鶡鶞鹟鹞鵧鰆麪麨鵧

鶮鶬龹龷龋龊鰺鵽鳹麺鼎

髗鼤鴓鶮鶬黏鹿龜鷍龆鳻鰲齣 \modules\custom\yunke 龆鴪龭鵧齣鴧 yunke 鴢龆齿 yunke.theme 鹟鹞齸鶮鶬龹龷龋龊鹑鹍龕龓鼎

function yunke_theme()
{
    return [
        'yunke' => [
            'variables' => ['title' => null, 'msg' => null],
        ],
    ];
}

鶥鬻鲿鹑鹍鸒黏鹿鮔鮐鴧 yunke 鴢鼛龹龷龋龊龆鳛鵈齿 \modules\custom\yunke\templates 齸鰀體鼨龹龷龋龊鼛鰜鰘龜龙鹟鹞龆鹟鹞鵧齣鼎鴧 yunke.html.twig 鴢龆鲶鲕鸗鼖鼎

{% if title %}
  <h1>{{ title }}</h1>
{% endif %}
<div>{{ msg }}模块中的模板</div>

鳛鵈鷞鷚鰀體黏鹿龹龷麪麨龆鳻鰲齣鼎

\themes\custom\yunke_theme

鴪龭鵧鶮齣鼎 yunke_theme

齿 info 鹟鹞齸鬎鶮鼎

base theme: bartik

鶥鬻鷞鷚鸝鼚齿鰜鰘鼛 bartik 龹龷鶖髊鸶鵽髉鷞鷚鼛鱢鸔

鳛鵈鶮鶬黏鹿鵽鳹鴧 yunke 鴢龹龷龋龊鼛龜龙龆鳻鰲鼎 \themes\custom\yunke_theme\templates 龆鹟鹞鵧齣鼎鴧 yunke.html.twig 鴢龆鲶鲕鸗鼖鼎

{% if title %}
  <h1>{{ title }}</h1>
{% endif %}
<div>{{ msg }}主题中的模板,主题生效中</div>

鳛鵈鶮鶬黏鹿髆髅龭龆鲛鲘鸗鼖鲶鲕鼎

        return [
            "#title"=>"yunke title",
            "#msg"=>"yunke msg",
            "#theme"=>"yunke",
        ];

鳹齿鲿鸝鼚鲡鴮鱢鸔鸒龆骿鴌鶥鹿髆髅龭龆鲡鲡鲺鸔

鳛鵈龂鸶鹟鴓鶮鶬鼛龹龷麪麨鮢鲼鰺鴨齣鰜鰘龆鱇鲡鲡鱢鸔

龏鹑鳡鼎齿鼨髧骽齸鳳鳰鴩鴨鼮鳭鳪鴲鶉齄鶖鼶鼛龜鷍黓龹龷鮢鷥齊麢麟齊鴨鶮鬨鵦齴

骼骸鼎

骶鯆齖鼛骴鰏龡黓 css/jss 鼾齿麽黏鹿魩魦鼊龰鼛龆鹺鷢鼶鼢鼞鵈鸊鼛骯鬜鼬鰄鳎鼊龰 attachments_processor

本书共88小节:

评论 (写第一个评论)