20. 渲染上下文RenderContext、渲染器renderer

drupal 龫龧龤龡龟龜龚龘龗龕龫龓龏龋龇龅龃龂龁齿齾齽齺龋龚龘龗龕齹 main_content_view_subscriber 齝齛齘齔齿齾齐齍龡齌齈齆龋齃齂鼿鼾鼼龫鼺鼹龋鼸龇龅鼴鼲鼮鼪鼩鼧鼣龫鼺鼹龚龘龡龋龇龅鼢鼡鼞鼜鼛鼚鼗鼺鼹龚龘龡龋鼕鼔齹鼮鼐鼏齔龡龫 main_content_renderers 鼎龗鼌鼋龋鼈鼅 html 鼺鼹鼧鼣龫鼁鼀黽 id黻 黹黸 main_content_renderer.html 黳龫 html 鼺鼹龚龘龡龋黯鼔黬鼩龫 html 鼺鼹黩鼋黥黡點鼁齃龚龘龫龋齃鼸龚龘黚黹黗鼗黓黏黍黋龚龘 body 黈黅龋黄黂龚龘 html 黈黅龋鼈鼅黯鼔鼸 html 龫龚龘麾黹齂龚龘黻

麼麹龫麷麳鼁麱龚龘龡麮麭龫龋齃麬麨鼸龚龘龗龕麥麤黹 html 麢麠麜龋麙麘龫齛麗麓鼁麑鼗龚龘龡黻

麐齆麏齃鼁麍麌麷麳龫麉麐黋齆麏麈麆麅麃 :

麁黋鼁龚龘龗龕龋鹾鹻齃鹸齍鹶麙龇鹵龫鹱鹯鹭 Drupal8 鹦鹢黚鹞鹜龚龘龗龕齝 render array 齌鹚

鼈鹗鼁龚龘鹔鹓鹒龋鹓鼋鹏鹌麈鹓龚龘鹔鹓鹒黍

渲染上下文

鹋鹗龚龘龓龋龚龘龗龕龫龚龘鹊鼲鼁鹆齂鹅鹄鹃鹀龫龋鸾鸽鼩鸺鸷龫鸵鹅鹄龋齃鼧鼣鸱 html 黩鼋鸰鸮龋麱鸬鹅鹄龚龘鼩鸵鹅鹄龋麑鼗鹊鼲鼅鸷黗鼗鸫麗麉麐麏鸧黍

1 黍鸟鸝鸫麗龋黹鼛鼞鸙鸗鸖龋鹋鼗龚龘龗龕鸕龚龘麈鹗龋鸔鸐鸎龫鸍鸌龋鸋鸈鸆龃鸂鹗龚龘龋麑鼌鸵鹅鹄龫鸟鸝鸗鷾鼸鷻鷷鼩鸬鹅鹄龋鷵鷲鸵鹅鹄麈鷰龓黂鷭鸌龋鷩麌鸬鹅鹄龫鸟鸝龓鷦鷤鸆鸖鷢鹊麈鷰龓黻

2 黍鷜齺鸫麗龋鹋鼗鹅鹄點鹸鷘鼮鼐鷔鷓麐鷑鼩龫 js css 鷉鷜齺龋麉麐鷈鷇鸺鸷龫麑麆鷜齺龋鷘鷄鷀鼩鶼鶹龫黩鼋鹔龋麑鼗鷈鷇鹊鼲麓鶸鶵龚龘鹊鼲鶴鶱龫黻

黹鼛麏鸧鷘鹔黗鼗鸫麗龋龇龅鼮鼐鼛麈鼗 BubbleableMetadata 鼧鶬齝 Drupal\Core\Render\BubbleableMetadata 齌龋麢鼋鶡鶝黹黸鹸鶜鶙鹅龗鼿黳龋鹋鼗 BubbleableMetadata 鼧鶬點鼧鼣麈鼗鹅鹄齝鷌麾黹龚龘龗龕龋鹸鶕鸷鸵鹅鹄齌龋齃鶒鶕鸱鶏鹅鹄龫鸟鸝龗鼿鶌鷜齺龗鼿龋鶋齂鼿齃龫鷑鶈龋鹯鹭麑鼌鼸齃麾黹黸龚龘鶆鶂鹅龗鼿黳龋黹鵾麌鵽鼛 BubbleableMetadata 麑麌鼗鵼麢鵸鵶黹鵾麌鼁鶜鶙鵶麑鶆龚龘龗龕龫鵵鵴鵰鵯鸷鹾龇龋鷲鵬鵫鹊鵧鵰鵤龗鼿鸰鸮麑鵡鵝鼲龃鷵鵙鵗鵖鶜鶙鵵鵴龋鵓鵫鹊鵶鵓鹾龇黂鼋龃鵑鵎鵋黻

鼧龚龘龗龕龫龚龘齝鵵鵴齌鼁鹆齂鹅鹄鹃鹀龫龋齃鹸鸖鸷鵇鵅鵃鸵鹅鹄龋鹋麈鵃鷤鹸鸖鸷鵅鼗鵂鹵鸵鹅鹄龋龚龘鵂鸆鼁鼸鸬鵃龚龘麮黂鸂鹃鹀龚龘鸵鵃齝麑鴾鴽鴺鴶鴳黋鵰鵯齌龋鴯鼁鴫鷑鴩鴶鴳黋鵰鵯齝鼸麈鼗鹅鹄鶌齃龫鸺鸷鸵鹅鹄龚龘麮鴨龃鹃鹀龚龘鴦鴤鹅鹄齌龋鷲鵬鴣黸龚龘黳鷵麳麈鼗鴡龋齃鼸鼏鹅鹄鷦鸆鴝鴚鴖鷌鴕鴓龋鼕龫鴏鴍鴉鴅麮鴂麠鴁鳿鳾龗鼿鸰鸮龋鶴鳽鹔龇龅麓鳺鳸鼛麈鼗鳿鳾鼧鶬鳶鳲鳮麑鼗鴉鴅龋鹋鼗鹅鹄鼧鼣鸱麈鼗 BubbleableMetadata 龋麑鼗鴡鼏鴚鴏龚龘麷麳龫龓龏龋鸕麉麐鼸鹅鹄鼧鼣龫 BubbleableMetadata 鼧鶬鼏鳿鳾鼧鶬鼅鳪鳨鳧鳦鴖鳧鴁鵂麓鸖麏鸧鹔鼋黗鼗鸫麗龋麑鼗鳿鳾鼧鶬麓鼁麙齛麗鳢龫龚龘鹔鹓鹒鼧鶬黍 Drupal\Core\Render\RenderContext 龋龶龚龘鴚鳨麈鼗鸵鹅鹄龫龓龏鳪鳨麈鼗鳞龫 BubbleableMetadata 鼧鶬鼩鳿鳾鼅龋龚龘麮黂鳚鳘麑鼗鼧鶬龋龶鳔鴖麑鼗鹅鹄龫龓龏鼸 BubbleableMetadata 鶌鳿鳾鼅鳒麈鼗 BubbleableMetadata 鴁鵂龋麑鼗鴁鵂鴍麳麓鼁鶜鶙龋齃鼸鸵鹅鹄龫鸟鸝龗鼿鶌鷜齺龗鼿鳏鼩鸬鹅鹄龋鶱鼏鳌鳊黹鵾麌鴾鴽鶜鶙鼛鳇龋龚龘鹊鼲鼅鸟鸝龗鼿鳃鳂鼪鹔鳁鸾龋鷜齺鷤鴂鲽鷈鷇鼩麈鲺黻

麑鼌麉麐鲹鲶龫鼁黍黸龚龘黳麑鼗黸鴡黳鼏龚龘麮鲵鼗鹅鹄龋鳚鳘龶鳒龫 BubbleableMetadata 龓龋鷤鹸鸖鲲鼿 BubbleableMetadata 鼸龚龘鸰鵬鴚鴏鸟鸝龋麑鲯鹋鼗鹅鹄鸕龚龘麈鹗龋鹋鼗鲮鲫鸟鸝鲨齺龫鸵鹅鹄點齹鲧鲤鸟鸝鼛龋麑鲯鲣鲣鼞鸙鼛龇龅鸗鸖黻

鹏鹌麮鹔鼋龫鲠鲟麅麃黂黯鼔鳶鲝麈鹓龚龘龡鼁麍麌麷麳龫黍

渲染器

龚龘龡龫鼀黽 id 鼁黍 renderer

鲜黍 Drupal\Core\Render\Renderer

鶴鶱鼛龚龘龡鲙鲗黍 Drupal\Core\Render\RendererInterface

鸷鷘鹓鸮鲎鼎龗龋鷘鼀黽 id 鲊鴖黍

controller_resolver 黍麏鹞龚龘龗龕鼅龫龜鲉龋鲆龧龤龡麏鹞龡

theme.manager 黍齛麗龇龅龋鴚鴏齛麗龚龘

plugin.manager.element_info 黍鷑鹻鲁鵽鹅鹄龫鼢鼡鲀

render_placeholder_generator 黍鱽鱹鱷鱶麠龋鱷鱶麠鼾鲝龚龘龗龕齛麗

render_cache 黍鱵鴏龚龘鸟鸝

request_stack 黍鼾鼼鳿鳾龋鷑鹻鲁鵽龶鳒鼾鼼龫龚龘鹔鹓鹒龋齃鷘鼾鼼鼧鶬黹龗龕鱭龋鱪鸝鼏鱩鸗龗龕鼌黻

鷘鱥鱢鱠龫龚龘鹔鹓鹒鱥鱷鱶麠鲨齺鱟鳸龗龕黻

drupal 龫龚龘龇龅鼁麈鼗鵇鲣龫龇龅龋鱜鱛鼧鶬鱟鴁麷麳龋麱鹻麘鱚鱖鱒麙齛麗鸆鹏鹌鷘鹔鼧鶬龫齘齔龋鶋鸆鷑鱑鱐龋鼕鼔鸆鷻鷷麙齛麗龫齆麏龋鼕鼔鼸鼏黂鱎齛麗鼅鹏鹌龋鶱鼏鸕麉麐麅鱌鼕鼔龫麳鷑鲫鱉黻

龚龘龡龫鱅鱐鱃鵯鼁 doRender 龋鼏麑鼗鱃鵯鼅鸖鳌鳊龚龘龫齛麐麷麳龋鹓鼋鼁鼧麑鼗鱃鵯龫鼴鼲鳢鳌龋鼾鼧鱂鸱鼲鰾鲝黍

Drupal\Core\Render\Renderer::doRender

麱鹻麐鷔黯鲉鷑龚龘鸵龗龕龋鸺鷘鼈鰼鰻鼗鼎龗 $is_root_call 鳲鳌龶鳒鲉鷑鼁鸋齈鹻鷔黯鸾鸽鲉鷑鼅龋鰸齘鲽鴫鷑龋鵂鸆鼁鲊鼏龚龘齂 html 鹅鹄

麑鼌鷘鸎鰷黍 $elements 鴽黹龚龘龗龕鳶鳢鳌黍

鷲鵬 $elements 黹鳞鰴鲙龟龜鳞麜

黋鴚鴏鰰鰭鰫鰪

鷲鵬鵓鸷鳺鳸 $elements['#access'] 龓龋鲝鸷鸍鰡鸫龧龤龜鲉 $elements['#access_callback'] 龋鷲鵬鸷鱵鴏龜鲉龋鼸鸰鵬鰝鲀鰜 $elements['#access']

鷲鵬 $elements['#access'] 鴂鷉黹 false 龋鸈龟龜鳞麜龋鷲鵬黹 AccessResultInterface 鼧鶬龋鼸鼈鸟鸝鲲鰗鷄鷀鼩龚龘龗龕龋鷘鰓鰰鰭鰐鰍龋鰡鸫鸰鵬鸆鰌鰊龫鰉鷤龟龜鳞麜黻

鷲鵬 $elements['#printed'] 鸆黹鳞龋鳢鳌鰈鰄齹龚龘鹊鼛龋鰴鲙龟龜鳞齝鰁鯾鼡黹龟龜 $elements['#markup'] 鳚鯺齌黻

准备开始渲染实质性工作

鵽黬鹔鹓鹒鳿鳾鼧鶬龋齃鷑鹻鶆鶂鱜鳂龚龘龗龕龫鸟鸝龗鼿鶌鷜齺龗鼿龋鳪鳨麈鼗鯹鹀龫 BubbleableMetadata 鼧鶬龋麢鼋鶡鶝鼁黸鹸鶜鶙鹅龗鼿黳龋鯸鷑鶈鶌鰴鯴鱖鱒鰁鯾麑鼌鶡鶝黹黍黸龚龘鶆鶂鹅龗鼿黳龋鼁鷲鯲鶆鶂龫鵸鵶鶸鶵龚龘鸾鸽鹊鼲龋鹆鶼鼌鵃鸵鹅鹄鶜鶙鼩齂鸬鹅鹄黻

鷲鵬鸷 $elements['#cache']['keys'] 鱩鸗鷌鯾鼁齂龚龘龋鸈鴁鵂鯰鱟鳸龫鱢麐鸟鸝鹔鹓鹒黻

鷲鵬鳺鳸鸷 $elements['#cache']['keys'] 鸈鯯鯫鹆龚龘鸟鸝鼌鼋鲁鵽龚龘鸰鵬龋龚龘鸟鸝鼌鼋龫齘齔點鼁鵓鸷鰄鹊鱷鱶麠鯪麤龫龋鸺鷘鷲鵬鼁鸾鸽鸵鹅鹄麮鯧黂龫齂龚龘龋鸈龟龜鳒麐鴚鴏鱷鱶麠鯪麤黻

鷲鵬鸝鼏 $elements['#type'] 鸈鷜鷀鹅鹄龫鼢鼡鲀龋鼈鼅鷲鵬鳺鳸鼛 $elements['#defaults_loaded'] 鸆黹鳞鼸鯦鯢鷀鯠龋麑鼏鲵麆鱃鼋鼁鸷鷑龫龋鷵鷲鳲鯝 API 鼌鼋龫 form_builder()黻

鯒鯏鼁鸋鳺鳸鯎鯊鸮鯆龜鲉 $elements['#lazy_builder'] 龋鵂鰫鰪齃龫鴁鵯鸗鯁齃龫麳鷑麓鼁鯎鯊鸮鯆龚龘龗龕龋鼈鲀鸕鸖鼁黗鼗鹅鹄龕麭龫龗龕黍龜鲉鱥龜鲉龫鼎龗龋鼎龗鹸鷘鼁 NULL 鷌鯾黈鰷鲜鮵鲀鯁龶鲊鼮鯎鯊鸮鯆龓龋龚龘龗龕鸆鸖鷤鸆鼣鶏鸷鸵龚龘龗龕龋鸵齘齔鼣鶏麱鯎鯊鸮鯆龜鲉鱽鱹黻

鯒鯏鼁鸋麉麐鮲鷑鷔鴍鱷鱶麠鵤龤龋鷲鵬麉麐龋鸈鳺鳸 $elements['#create_placeholder'] 黹鮱龋龶 $elements['#create_placeholder'] 鸷鳺鳸鮯黹鮱龓 $elements['#lazy_builder'] 鱢鱠鸝鼏龋鱒黹麉麐鷑齃龫鸰鵬鮬鯪麤鱷鱶麠黻

$elements['#create_placeholder'] 鸷鳺鳸鮯黹鮱龓鼧 $elements 鮪鯆鱷鱶麠黻

鷲鵬鸝鼏 $elements['#lazy_builder'] 鸈鲉鷑齃鳶鸮鯆鳘鹅鹄鷘鮧鯪鱖鹅鹄龋鼸鱖鹅鹄龫鸟鸝龗鼿鳺鳸鼩鳘鹅鹄龋鳺鳸 $elements['#lazy_builder_built'] TRUE 鷘鳲鳮鰈鰄鲉鷑鼛鯎鯊鸮鯆黻

鷲鵬鳺鳸鼛 $elements['#pre_render'] 鸈鲉鷑齃鼔龋鰌鰊鼈鮠鮜龚龘龗龕黻

鷲鵬 $elements['#markup'] $elements['#plain_text'] 鸆黹鳞龋鸈齈齆齃鼔龋 $elements['#plain_text'] 鴳黋鳂鳚鸙龋鱪鮘鸷麈鼗鮔鴂龫 $elements['#markup'] 龋鼈鲀黹 markup 鼧鶬黻

规范化当前元素的渲染跟踪元数据

鰫鰪 $elements['#printed'] 龫鳺鳸龋鰌鰊 $elements['#pre_render'] 鶹鯢龚龘黻

鷲鵬鸝鼏 $elements['#states'] 鸈齈齆鮐鮏鮌鮊黻

鰪鮇鴖鸵鹅鹄齝鸵龚龘龗龕齌龋鷲鵬 $elements['#children'] 鸆鸝鼏鸈鳺鳸齃龫鯹鹀鲀黹鳞麢麠麜龋齃鮧鳲鸵鹅鹄龫 html 齘齔麢麠麜黻

鷲鵬鳺鳸鼛 $elements['#theme'] 龋鸈鳢鳌龚龘龗龕麉麐麱齛麗龇龅鮬龚龘龋鲉鷑齛麗龇龅鴚鴏龚龘龋麑鷤鼸龚龘鸵鹅鹄龋鵂鼸鸰鵬鰝鲀鰜 $elements['#children'] 龋鹸鷘鳺鳸 $elements['#render_children'] 鮆鯢鲉鷑齛麗龚龘黻

龶鵓鸷齹齛麗龇龅龚龘鷌鳺鳸鼛 $elements['#render_children'] 鮆鯢齛麗龚龘龋鮅龓龶 $elements['#children'] 黹鳞龋鸈鴚鴏鸵龚龘龋鷔黯鲉鷑龋麑鼌鼁鸾鸽龚龘龫鹃鮂黻

鷲鵬鸝鼏 $elements['#markup'] 龋鼸齃魿鷀鼩 $elements['#children'] 鳒鼋龋鷲鵬鼁齛麗龚龘龫鰉龋鮅麷麳鼣鶏麱齛麗龇龅麮麭黻

鷲鵬鸝鼏 $elements['#theme_wrappers'] 鮯鵓鸷鳺鳸 $elements['#render_children'] 龋鸈麱齛麗龇龅鱵鴏齛麗鶒魻龚龘龋齃魷魵鼏鰈鰄龚龘龫鸵鹅鹄魱鼋鶒魻麈麆鼈鼕鹅鹄黻

鷲鵬鸝鼏 $elements['#post_render'] 鸈鱵鴏麑麆龜鲉黻

鷲鵬鸷鳺鳸鳒魰 $elements['#prefix'] 鷌黂魰 $elements['#suffix'] 鸈鮲鷑齃鼔龋鶼鶹魬麭龚龘黂龫 $elements['#markup'] 龋齃鼁麈鼗 Markup 鼧鶬黻

鱵鴏龚龘鹔鹓鹒鳿鳾龫鳚鳘龋麼麹鼁鼸鮧鳲麙鹅鹄龫 BubbleableMetadata 齝龚龘鶆鶂鹅龗鼿齌鸎黹鶼鳘龋鱒黹鹔鼋鰊鵅鹊鼲鹸鷘鮜鸎麑麆鲀龋鷵鷲 #pre_render #post_render #lazy_builder 鷉鷉黻

鸟鸝鰈鰄齹龚龘龫龚龘龗龕龋鼏鷘鹔魩鼗鹊鼲鼅 $elements['#cache']['keys'] 鸆鰌鰊齹鮜鸎龋麉麐鸆魥龫鸟鸝 id 鹸鷘鴫鷑鸟鸝鹔鹓鹒鮬鶴鶱黻

鷲鵬鼁鸾鸽龚龘鸰魤黂龫齂龚龘龋鸈鴚鴏鱷鱶麠鯪麤龋鼸鮱鰐龫鱷鱶齘齔鲀龚龘黂鯪麤鱷鱶鸎鰷黻

鱵鴏鶜鶙黍 $context->bubble() 龋麑鼁龚龘鶆鶂鹅龗鼿鶜鶙龫鹾鱭龋鷤鼁龚龘鹔鹓鹒鳿鳾鼧鶬龁魟麳鷑龫鱅鱐黻

鶼黂黈魜 $elements['#printed'] 黹鮱鳲鳮鰈鰄龚龘鹊鼛龋龟龜 $elements['#markup'] 龋齃鮧鳲龚龘黂龫麢麠麜鲀龋鷘 markup 鼧鶬龫鱃鼹鸝鼏黻

补充说明

鼈鶴 drupal8 龫鸺鸷龧龤龡點鼁鶒魻鼏麈鼗龚龘鹔鹓鹒鼅鱵鴏龫龋魙龫鼁麏鸧鼏龧龤龡鼅鰴鲙龚龘齘齔魖鷭 BubbleableMetadata 龫鸫麗龋鸷魕鼏 drupal9 鼅魷鹊魒鯢鼏龧龤龡鼅鰴鲙龚龘麏鸧黻

龚龘龡鴚鴏齂龚龘黂 js css 鷜齺鰸魷鹊鱷鱶 tokens 鮧鯪龋鼏黂鱎鼴鼲鼅鴨龃鮱鰐鷜鷀麑麆鷜齺黻

doRender 鷉鱃鵯龫 $is_root_call 鼎龗鮧鳲龶鳒鲉鷑鼁鸋黹麈鼗鸾鸽鲉鷑龋鵂鸆鳲鳮鼏鴚鴏 html 鹒魑龫齂龚龘龋齃鼁麈鼗魍鼲魉魅龋鰸齘鲽鴫鷑龋鼏鸾鸽鹊鼲鼅鸆龃鴚鴏鱷鱶麠鯪麤黻

龚龘龡龫 $contextCollection 鱩鸗龋齃鼁 SplObjectStorage 鼧鶬龋鱪鸝鼾鼼鳿鳾鼅鹋鼗鼾鼼鼧鼣龫鼾鼼鹔鹓鹒鳿鳾鼧鶬龋鲹鲶齃鼁鬽鮏鱩鸗龋麑鲶鬼鸱鸆鬸鵅鬴鼗龚龘龡鶴鬳龋龚龘鹔鹓鹒鱪鮘鹋鼗鼾鼼鸕鼧鼣麈鼗龋鼏 executeInRenderContext 鱃鵯鼅龃鬱龓鳺鳸麈鼗鹔鹓鹒龋鷑麮鬭鬬龋黄黂鬪鱖鹜鳒龫鹔鹓鹒黻

鬩鲉麈鹓鼏龚龘鹊鼲鼅 $elements['#cache']['keys'] 鸆鰌鰊齹鮜鸎黻

本书共63小节:

评论 (写第一个评论)