23. 渲染占位符及其产生器

drupal龪龨龥龤龢龡龞龛龙龗龓龗龏龌龈龆龄龂齾齻齹齸齵齴齰齬齫龏龆龄齧齤齠龨齝齙齗齝

齵齴齓齒齑齍齋齇齅
1齅齀鼽鼼鼹鼶龏鼲鼮鼲鼭龗齸鼩鼩鼨鼲鼧鼦鼥鼲鼭齸鼣鼟鼲鼝鼹鼶鼩鼛鼘龗龨鼗鼔鼥鼲鼭齸鼟鼓齀鼲鼏龗龨鼗鼍鼥龏鼋鼇齧齤鼄鼀齤鼲鼏黼黻黹龏鼥黷黴龗齸黳鼥黲黱齸黹黮黪黧黣黡黝齍黙黗黓黒黎
2齅齀黉黅黂黁麿麻齝麷麶麲齸麮麫麨齫黁麿齸麥麤麢麞齸黹鼝鼽鼼齧齤龗麛麚麙麗齫黎齸龪龨齧齤鼥黷黴齸麕齑麒黁麿麻齝麷麶麲龗麑麎麊麇麆齰齸鼥麅麁齧齤
3齅齀黉黅黂鹼麲齫黒鹸齸齧齤鹶鹲鹮鹬鹫齸鹧鹤鹣鹠齧齤鹞麁麛麚齸麕齑麒黹麑麎黅黂麊麇麆齰鼥麅麁齧齤


鹚黝鹗鹓鹏鹌齸鹉鹤鹇黪鹅鹂齫麗鸿齧齤鹏鼋鼦齅黝齍黙鸾鸻鸸鸾鼽鸵齸鸲鸰黹黉鸯鸭鸩鸦齧齤鼥黷黴鸣鹠黒黎
鹗齑鸢鸟龢龡龞龛龙齸麒黹黉齧齤鼥黷黴龗黅黂麎鸛麆齰齸鼇鸯齰龗鸚鸙鸢鸟鼲鼝龢龡龞齸鸗鸖鼩齧齤黷黴龗黅黂齸龥龤鼽鸒齧齤鸑麆黓鸐鸖鸏鸍鸐龢龡龞鸉鸇鸃麒齧齤鼥黷黴龗黅黂龥龤鸖鸂鷾鷼鷺鷸鷴
麕齑鷰麆龥龤黓鷯龗龢龡龞龛龙龏鷮鷫齀龨龗齸麚鷧黝齬龏麒龄鷦鷣鸾龄黗黓龗黅黂鷡龪龨齧齤鼥黷黴龗黅黂鷠鷞鷚龥龤齸鷙鷘齧齤齻齹鷕
鷔鷓鼹鼶鼨麑麎龏鷐齧齤黷黴鸒鷌鷈龨龢龡龞龗黒鷅黣黡鷃Auto-placeholdering鶥鷡鶤鷦龢龡黒鷅鷠齸鶠龏鶜鹮鶤鷦龗鶙黻齫鶘鶗鸐龥龤鶕鸟
黂鶑鶐黓鼄龗renderer.config齫龏鶊鶕鸟齸鶆鶅鹫鼟齍齅鷡鶃鶁鵾黅黂鵻鷠

麕齑鷰鵷鼇auto_placeholder_conditions鼄麕齑鵮鵬鹤鵩鵥齧齤鼥黷黴龗鵢龓鵡鵞鵚鵬龌鶆鶅鶕鸟龈齸黹黉麒麅麁龢龡龞鷼鷺
鼋鶕鸟麢鵙龗黅黂齫鼋鶗鸐鵘鵔龗鵐鵏鵍鵉齸黹黳龏鵘鵔鵆麿龗鼲鼝鵅鼋黅黂鷕
黹鼝鶆鶅鹫龏鼇core.services.yml鼄鵚鵬龗齸龨鼗麕齑鼇\sites\default\services.yml鼄鶤鵬鴶齸鶠鹤鴳鴰鴮鴬龆鴨龗鶕鸟

[renderer.config] => Array    
                 (    
                     [required_cache_contexts] => Array    
                         (    
                             [0] => languages:language_interface    
                             [1] => theme    
                             [2] => user.permissions    
                         )    
     
                     [auto_placeholder_conditions] => Array    
                         (    
                             [max-age] => 0    
                             [contexts] => Array    
                                 (    
                                     [0] => session    
                                     [1] => user    
                                 )    
     
                             [tags] => Array    
                                 (    
                                 )    
                         )   

下面来看看drupal具体是怎么实现占位符机制的:

鼋龪龨龢龡龞龛龙龗黅黂鴦龏齧齤鼥黷黴龗齸鼇鴢鷫龗龥龤鴞鷅鼄麒麗黹麑麎黅黂龗龥龤麊麇麆齰齸鼇鸂鸖麅麁
龌鶊龂齾鴝龥龤黓鷯鵬鴶龈鼲鼝黣黡鷞鷚鴜鴘龗鴕鼔齅$elements['#lazy_builder']齸鶠龗鹫龏鼲鼝鳿齀鳽鼝鼧鼦龗黓鷯
鳼鼲鼝鼧鼦鳻鼘鷸鳷齸鳼鳴鼝鼧鼦鳻鼘鷸鳷龗鶐黓齸鶐黓鵞鳰龙龌鼩鸻鳭黓鸐鳬鳫鳧NULL
鼋麅麁龢龡龞龛龙龥龤龗黅黂鳡鳝鸢鸟鷞鷚鴜鴘齸龪龨鷸鳷鳙鳗黅黂
鸢鸟龈鷞鷚鴜鴘龗龥龤黓鷯鳻鼘鳕龥龤黓鷯龗鹗齀黅黂鵡鸲鷞鷚鴜鴘鷸鳷鳙鳗齸鹶齀黒鵙龗鳔齻黳鹶齀鳓鼧鼦
鷺鳏鳋鳈齫龏鳕龥龤黓鷯鼥鳄鳂齀'#lazy_builder','#cache','#create_placeholder'鲽鲺龗鼧鼦齤鼇
鲸麗黹鼭龗龥龤黓鷯麅麁龥龤鼽龂齾鷔鷓鶠齹鼥齹齙鳕鼥鳕鳙鳗龢龡龞齸鼟鼓麕齑鲷鲳黒龥龤齸鲰鼇鲯龥龤黓鷯鼄鳙鳗鼲鼝龢龡龞鷡麙鲸鸰鲮鼽鲫鷸鼲鼝龢龡龞鲨龌龥龤鲦鼓markup鷠
鷔鷓齙鳙鳗龢龡龞龗鲢鲨龏鸲龥龤龢龡龞鳙鳗鶑鵐黪龗齸鶠鼇黂鶑鼄龗鲠鲝id龌render_placeholder_generator
鳬鵐黪齅Drupal\Core\Render\PlaceholderGenerator 鶠鵐黪龈鲌鲉齅Drupal\Core\Render\PlaceholderGeneratorInterface
鳕鲌鲉鹼鲃鲁齸鳿齀鹏鼝鸙鱾齸麎麶麗鸿鸰齹鼥齹鷡龂齾齹鷐鱺鴘鷠鸾鳕鼥鳕鷡鸍鸐龥龤鶕鸟鷔鷓龏鷐鸿鳕鱺鴘鷠鸾鱺鴘龢龡龞鷡鱶鱵齵齴鱺鴘鲢鲨鷠
齰鷰鼲齍龥龤龢龡龞鳙鳗鶑龗齵齴鵐黪齅
鱴鱰龡鸰齅Drupal\Core\Render\PlaceholderGenerator鷡鱮齅鼇麚龂鱭鸖鱩黙鱨鼄鵡龪龨鼔鱧鱥鸵鵚鱴鱴鱰龡鸟齸鷰鵷黹鱢鱠鱟鸿麕齑鱝黒鳬鱛鱘鶑鱗鱖黙鱓龡鸟鷠
canCreatePlaceholder鸙鱾齅鼋鱺鴘龢龡龞鳡鳝鼋齤鼇鷞鷚鴜鴘#lazy_builder齸齑鱏#create_placeholder鼥龌false鳧鼥鸢鸟
shouldAutomaticallyPlaceholder鸙鱾齅鶗鸐龥龤鶕鸟齰鷔鷓龏鷐鸿鳕鷈龨龢龡龞龛龙
createPlaceholder鸙鱾齅麕齑鷰鵷鷸鳷鶐黓龏鼲鼝鱧龞鱎鱊鱆齸鲫鷸龗龢龡龥龤黓鷯鳿鱃鱁齅#lazy_builder鸾#cache鸾#markup鸾#attached齸鱀鼄#markup鱃鱁龗黅黂齫龏龢龡龞齸麕齑鷰鵷鳷鰿鸉鸇

总结注意:

龢龡黅黂鸲鷸鳷鳙鳗齸鹗齑鷈龨龢龡龞龛龙鼽齸#lazy_builder鳡鳝齤鼇
鸢鸟#lazy_builder鼽鼟鼓齤鼇#create_placeholder鱀鹫龌false,麒鼥鹤鳙鳗龢龡龞齸鷌龏鰾鲌龥龤齸黹鷫龨鸰鸍龥龤
#lazy_builder鵚鵬龗鷸鳷鲫鷸龗龥龤黓鷯麒鼇鰼鲺鼲鼝龥龤黝齍黙鼄龥龤齸鶠龗鳓鼧鼦麕齑龏鰸鰶龗齸鼟鼓龏鹫鶘麅麁齧齤龗黅黂麒鹤鵞齧齤齸黹鰵鰲鸰龥龤龗鶤鰯鰮鰵鳷龨鵐黪
鸂鷾鲫鷸龗龥龤鼹鼶鹤黲鲰鹗齀龗齧齤鳔齻黓鸐齸鱃鰪龢龡龥龤黓鷯龗黓鸐齸黹黉黓鸐鹤鵞drupal龗鷦鷣齧齤鼮鰦龨鵷

本书共65小节:

评论 (写第一个评论)