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'] 鷤鯢鯟齲魽鷳黤

本书共71小节:

评论 (写第一个评论)