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龔鸈鸅齦齢鼵鱏龭鶕

本书共74小节:

评论 (写第一个评论)