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'] 鷟鯇鯅齯魛鷯黚

本书共88小节:

评论 (写第一个评论)