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'] 鷞鯯鯮齹魾鷭黧

本书共78小节:

评论 (写第一个评论)