80. 占位符策略placeholder_strategy

龵龱龰龭龪龩龨龤龡龟龝龚龙龗龔龒龐龏龎龌龋龉龆 $element['#attached']['placeholders'] 齝齚齖齔齓齒齎齊齉齇齄齃龚龙齂齁齀龝鼼鼸鼷龪鼴龵鼱鼰鼬鼪鼨龩龨龤龡龐 html 龩龨鼪鼨鼤龒龆鼠鼝 id html_response.subscriber 齝鼉鼆龵齒齎齊鼃鼁鼤龒齁齀龆鼠鼝鼀鼖 html_response.attachments_processor 齝龝龵龭龪龩龨龤龡龟龝龱龰龵 html 龩龨鼪鼨鼤黼黹黵黴黰黯黬鼪鼨鼤鼖

鼠鼝鼀鼖 html_response.placeholder_strategy_subscriber



黥黢點黛鼖



onRespond

黖黕黒鼖 5-1

黆黬鼪鼨鼤黥黢龏龎黂麿鼠鼝龝麻麸麷麳麱麰齚黵黴龏龎黂麿鼠鼝麮麫麨龏龎龋龉龆麦麣齝麟麞麜麙龱龰龒龐麗齄龏龎黂麿鼠鼝麓齃麏麎龏龎黂麿鼠鼝麌麋麈黥黢龝麦麣麄

麏麎龏龎黂麿鼠鼝鼖

鼠鼝鼀鼖 placeholder_strategy

麂鼖 Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy

鹯鹭點黛鼖 \Drupal::service('placeholder_strategy');

鹠鼠鼝鼬龵 core.services.yml 龒鹟鹜龐龝鹘麣鼖

  placeholder_strategy:
    class: Drupal\Core\Render\Placeholder\ChainedPlaceholderStrategy
    tags:
      - { name: service_collector, tag: placeholder_strategy, call: addPlaceholderStrategy }

鹐鹏鹍黖黕黒麌麋龱龰龒麗齄鼉鹊鹇 placeholder_strategy 鹀鸽龐鼠鼝龆龏龎黂麿鼠鼝齝龝麈鸺鸶黥黢龝黥黢鸲鸱鹘麣鼖

鹏黖黕黒鸺鸶黥黢鸰龏龎黂麿鼠鼝龝龗鸬鸨鸦黖黕黒鸨鸢龝鸨黕黥黢龝龵鼃鼁麏龒龝黹鸞鸜鸚齃鼃鼁鸗鸕龐龏龎龌龝鸒鸎鸍齃鸋鸈鸇鸅鸞龐龏龎黂麿鼠鼝龝鸂鼼黖黕黒鸀鷽鷺龝鷷黬鷶鷴鼃鼁鷲鷯鸅龝鷬鸗鸕齃鼃鼁龐龏龎龌麄

鷨鹟鹜龏龎黂麿鼠鼝鼖

鹟鹜黯黬麂龝麞鷤齚麣鷢鷡鼖

\Drupal\Core\Render\Placeholder\PlaceholderStrategyInterface

麈鷜齔鹟鹜鷙鼠鼝龝鸇鷕鼠鼝鹀鸽鷑鼖鹇 placeholder_strategy 鹄龝麈鷎鹟黯黬黖黕黒龆鷷龗龝麰齚鷑鷍龗齝麄

麂點黛鼖 processPlaceholders(array $placeholders); 鷢麌鸋鷌龐龏龎龋龉龝鷊鷉鼬龚龙龗龔龒龐齚麣鷅鷄鼖

$element['#attached']['placeholders']

鼬黯黬龗龔龝鷀鼀鷑龏龎 token 龝鷀鸬鶻鶹鷑鸕鶵龝麰鶴麦鶱龱鶭龐鶬龚龙龏龎龌鶫鼴鼤鶧鶤鶢

鷬鶡鸗鸕鸋鷌 $placeholders 龐鶟麋龝齇齄齃鸗鸕龐 token 鷜鸋鸈鸇鸅鶜龏龎黂麿鼠鼝鶘鶜鼃鼁龝鸗鸕龐鷜鸒鸎鶘鶜鸋鸈龝龵鹠點黛龒鶔鶑麰齚鶏龏龎龋龉鶋黢麫麨麟龏龎黂麿鼠鼝鶉鶈鶇龱龰鶃鶏龏龎龋龉龭龪龐鶁鶟麄

鶀鵼龏龎黂麿鼠鼝鼖

龱龰黵黴黰齚麣鶀鵼龏龎黂麿鼠鼝龝鹐鷊鼬鹀鵻鵸鵴龒鵰黯龐黯黬龏龎黂麿鼠鼝鼖

鼠鼝鼖 placeholder_strategy.single_flush

麂鼖 Drupal\Core\Render\Placeholder\SingleFlushStrategy

鹠鼠鼝鼬龵 core.services.yml 龒鹟鹜龐龝鹘麣鼖

  placeholder_strategy.single_flush:
    class: Drupal\Core\Render\Placeholder\SingleFlushStrategy
    tags:
      - { name: placeholder_strategy, priority: -1000 }

鹐鸒鵨鵦鵣鼃鼁龝鵡鵠鸒鵞龐鵝鷢鸗鸕麗齄齉齇齄齃鼃鼁龐龏龎龋龉龝鸂鼼鹐龨鹠鼬鵛鸅黯黬黥黢龐龝鶔鶑鷨鹟鹜龐龏龎黂麿鼠鼝龐黖黕黒鸒龨鹠鵙鶇鹇 -1000 鹄龝鵘鵔齇齄鵓鵒麟鹐鼬龱龰鶀鵼鹟鹜龐鵰黯黯黬龏龎黂麿鼠鼝龝黆鵐鵏鵍鷷黬龏龎黂麿鼪鼨鼤麞麜麙鵉鵆鷊齇齄鵨龝鷬鼬黵黴黰黯黬鷨鹟鹜龐鷌鷡麄

鵄鵃鵂鴿鼖

1 鴾龵鶀鵼麞鷤龒龝鸗鸕龐龏龎龋龉鸒鸎鶘鶜鸋鸈龝鹘鵒鶔鶑鴻鴷麫麨鹐鴳鴷鴱鹐鶘鶜鸋鸈鸇鸅鶜龏龎黂麿鼠鼝鴯鵆鴫鴧鴣麰鶡鸎鴷鴢鶴龗齚鴞鴛鷢麌龝鴗黆齂鷢鷡鹟鹜鼬鸒鶉龉龐龝鸂鼼鴓黛麞鷤黆鼰龐鴑鴐龝鷊鸒龨鹠黆鼰麞鷤龝黆鼬黯鴎鸒黖鴋龐鵨黛龝龨鹠龵龋鴈鵝鷢鼃鼁鴢龎麄

2 鴾龏龎黂麿鼠鼝鶻鶹龨鹠齚鼠鼝點麎黵黴龝龵龉鼤鴂鴁鳿鳽麌麋龝鴗鷊麰齚龵鳼黢龟黵黴龝鶵鴛鹘麣鳸鳶鳵麰鼖

\Drupal::service('placeholder_strategy')->addPlaceholderStrategy($strategy)

鴗鴑鷺鳮鵐鼖鳭黹龆 drupal8.5 齝麞鷤鳨鳧鳦鳤龝鹠點麎鸒鶡鸋鸈黖黕黒鶴龗龝鸺鳡鶇鶵鴛鳠鳞龝鸂鼼鳝鳚鷄鴛鼠鼝點麎黵黴麄

本书共88小节:

评论 (写第一个评论)