74. 主题协商theme negotiator

drupal 龥龤龡龟龜龛龙龘龔龒龏龌龋龉龅龂龀齿龥龤龔龂齼齸齵齲齰齮齬齫齩齦齤齠 pc 齤龔齜齚齼齸齵齙齕齓齏齌齈龔龒龏龌齆齄齤龛齃龅龂齂齁鼽龥龤龔鼺鼹龙龘鼷鼳齂鼲齜鼮龔鼪鼦鼢齆齁龀鼟龉鼝鼚龒龏龌鼙鼕鼑鼎鼋鼊龅龂齂齁鼽龥龤龔龡龟鼈鼇齲鼄鼽鼃黿黽黺黷黳黲龔黮齜齆 pc 齤黫齩齦齤龒龏龌黪齂齁黦黥黡龂齂齁龥龤龔黟黝齂齁龂黙黡龂齂齁黕黑龔鼋鼊黿鼑鼎鼽龔鼃黏齌黋黇鼪黆龀鼟龥龤黂黁麾龏龔麼麹黿麷麵麱麭鼽麫齫麨

drupal 鼚麦麣龏龌麡麠麟鼟龥龤龔麛齤齠麙麘麔麑龏龌齄麏麌鼄龀鼟黽黺龥龤麋麛齤黽黺黪 bartik 龔麙麘麔麑黪 seven 鹷龔鼺鹳齂鼎鹯鹫鼃鹨龅龂鹤麌鼄鼽黽黺龥龤龔齆龉鼝鼚龏龌齁鹣龅龂麟鼟龥龤龔鼃齌鹢麣鹤麡麠鹟龔鹜鹛龀鼟鹘麑齸鹔龅龂鹓鼟龥龤鹐鹏鹌鼄龀鼟鹘麑龅龂鹋鹛龥龤黿鹉龥龤黂黁鹅鹃鹂鼽龔鹢黿龡龟鼄鹀鼽龀鼟鸾鸺龔鼪鼦鼢龡龟鼚鸸鸴麟鼟龥龤黂黁鹅龔鹢麣鸱鸰鸯鸮鸬鸪鸨鹂龀鼟鸤鸠龔鸜鸚鸖鸕龔龀鸔鸸黂黁鹅鸑鸏鹌鼄鹜鹛鸍鸊鸇鼈鸅黂黁鹅龔黕鸄龏龌麏鼄鹀龥龤黂黁鹅龔齆鼹鼚麦麣龏龌鸀鷼鼑鼎鼋鼊麌鼄鼑鼎鹘麑鼽龥龤龔黮齜麛鷸鷷鷶鼽 pc 齤齠齩齦齤龛齃鷲鷱龥龤鹣龔麦麣麹龏龌鼙鼕鷮鷪鷦鼽鷢麘鷠鷜鷚鷖鷔龅龂鹓鼟龥龤麨

鷐鼎鷌麼鷉黏齌鷐鼎龥龤齠黕黑鷈鷅鼽鷁齃龔龏龌黋黇鼽麼鶾麘鶻鷌龥龤黿龀齿黕黑鼽鶹鶸龔鶶龡龟鶵鶴鶱龀鼟龥龤黿龀鼟鶯鶫龔鶩鹟黕黑鶧鸸鶦麟鶣鶟鶞 js css 鶚鶚鶘龥龤黂黁黿齆龥龤鶗鶔鶑麑鶍鶉鼽龔齆龀鼟龥龤麫龅龂鹓鼟黕黑鹜黿黕黑鶇鶃鶀鵿鼽鵼鵹麋麷龡鸠鼹鵶鷸鵵鵳鵰鹷龔龀鼟龥龤麫麱鸸鹘麑黕黑鵮鵫齸鹔黿龀鵨鼽龔齂齁龥龤鵮鵫鵧鵧齂齁龔麼齂黿龀鼟鵦鵥麨

麏鼄鹀龥龤黂黁鹅鷌

麼麹黿齆鼄鹀龀鼟鸾鸺龔鸯鼄鹀龀鼟鵡龔鵝鵚齆鵘鵕鵑鷅鵏齸鼽鷸鼊鼚龔鹔鵡鵎鵌鼪黆龌鵈鵇鵃鷌

\Drupal\Core\Theme\ThemeNegotiatorInterface

鹔鵇鵃鸸鴪鼟鴩齕鷌

applies(RouteMatchInterface $route_match)

鼙鼕鵹鴓鹌鼄黿鴏黏齌龅龂麷黂黁鹅龔鴍鴋鴊鴇黷龔齜齚鴍鴋 fasle 鹜鹛龥龤黂黁鼽鶍鶉鸍鴆鹉鴅鼈鼽龥龤黂黁鹅鷚鹃鹂龔龡龟黽黺鴁鳾鳺鳶麛龥鳴齈鼽鳳鹉鳰鳬鷦鵏鳪龔鼺鹔鴩齕麫鳧麦麣鳣龏龌鼙鼕鼹鵶鳢鳟鷚鸑鹌鼄

determineActiveTheme(RouteMatchInterface $route_match)

鴍鴋龥龤鼽鳙鷦鵘麋鷐鼎黿鳙鷦鵘鹷龔鳣龏龌鴍鴋 NULL 鳒鳏黂黁鳋鳇龔麼鸍龅黂黁鶍鶉鳃鳂鸰鸯鸮鲿鼽鴅鼈龥龤黂黁鹅

鷐鼎鷌齆龥龤黂黁鹅鼚麦麣齙黏鼪黆鵏龥龤鼽鲻鲷鲵鲲龔鹔鶍鶉鸍鹉鲮 access_check.theme 鲩鸾鸺齮鹃鹂麋鲦鼈鷸鹷麨

鼄鹀鲢鵡鼈龔齆 MODULE.services.yml 鼚鸍鹢鲚鲘黪鸾鸺龔鲦鵈龔鲖鼝黿鳂鸏鲮 theme_negotiator 鲩鷠鲕齠鸰鸯鸮鲓鼷龔齆齫鷦鲏鲍鲊鲇龡龟鴁麏齦鲅鶹鹢鹳鸱鲃鸰鸯鸮鸬鸪麨

龡龟鷷鱿鼽龥龤黂黁鹅鷌

龡龟黽黺鷷鱿鹟鱽鼟龥龤黂黁鹅龔龏龌鱺鱹鹢麣鼽鸾鸺鼄鹀齠鼪黆龔龌鵈黿鸱鲃鸰鸯鸮鶶鱵鷶鱲鸬鸪鷌

ajax 鱭麷鹘鷌

鱭鱩 POST 鱥鱣鼚鼽 ajax_page_state 鱥鱣龔鹢黿龀鼟鶟鱢龔鱡鵘鱠 'theme' 麋龥龤鳙鷦鵘鹷齠 'theme_token' 麋鱜鱚鱘鱗鹷龔鼃齌鱘鱗鱓鱏鸍龅龂 'theme' 麌鼄鼽龥龤龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.ajax_base_page:

class: Drupal\Core\Theme\AjaxBasePageNegotiator

arguments: ['@csrf_token', '@config.factory', '@request_stack']

tags:

- { name: theme_negotiator, priority: 1000 }

鸄麙麘 demo 鹘鷌

鼃鰭鵏鲮 block.admin_demo 鲩鳳鹉龔黡龂鹔鳳鹉鼚鳳鹉鱺鶟 'theme' 麌鼄鼽龥龤龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.block.admin_demo:

class: Drupal\block\Theme\AdminDemoNegotiator

tags:

- { name: theme_negotiator, priority: 1000 }

龡龟鰩鰧麘鹘麑鷌

鼃鰭鵏鲮 system.batch_page 鲩鳳鹉龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.system.batch:

class: Drupal\system\Theme\BatchNegotiator

arguments: ['@batch.storage', '@request_stack']

tags:

- { name: theme_negotiator, priority: 1000 }

龡龟鶟鼕鰥鰤鰠鹘鷌

鼃鰭鵏 'system.db_update' 鳳鹉龔龂鱩鶟鼕鰥鰜鰛鰤鰠鹣龅龂龔龏龌齆龉鼝鳬鵚鷸鼊鼚龅龂鳬鵚鰚鲮 maintenance_theme 鲩麌鼄龀鼟龥龤龔齜鰙鸸齲鼄鹔鳬鵚鰚鸍黡龂 'seven' 龔齜齚齲鵚黪 false 鸍龅龂黽黺麛齤龥龤龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.system.db_update:

class: Drupal\system\Theme\DbUpdateNegotiator

arguments: ['@config.factory']

tags:

- { name: theme_negotiator, priority: 100 }

麙麘麋鼈齤鹷鹘龥龤鷌

龂黙鸸 'view the administration theme' 鲻鲷龔鰖鰓鰏鼽黿麙麘鹘麋鳳鹉鼚鸸 '_admin_route' 鶗鰚鹷龔鹜鹛鸍龅龂麙麘龥龤龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.admin_theme:

class: Drupal\user\Theme\AdminNegotiator

arguments: ['@current_user', '@config.factory', '@entity.manager', '@router.admin_context']

tags:

- { name: theme_negotiator, priority: -40 }

黽黺龥龤鷌

麼黿鸰鸯鸮鰈鲿鼽黂黁鹅龔齜齚鰙鸸鼹鵶黂黁鹅鰇鸕鸸鰆黂黁鹣鰅黿鹤龅龂龔鹢鰅黿鴍鴋麛齤黽黺龥龤龔鸾鸺鼄鹀齜鵈鷌

theme.negotiator.default:

class: Drupal\Core\Theme\DefaultNegotiator

arguments: ['@config.factory']

tags:

- { name: theme_negotiator, priority: -100 }

鸀鷼龌鼢龡龟鷷鱿鼽鱽鼟黽黺黂黁鹅龔龏龌鶱鷶鰈鱵鼽鸰鸯鸮黿 1000 龔黽黺黂黁鹅鸰鸯鸮鰈鲿龔黪 -100 龔麦麣麏鼄鹀鼽黂黁鹅鸰鸯鸮黏齌鱺鱹鹢麣龌鰇鸕鰃鳶鼽鸬鸪龔鳶鱵鸰鸯鸮鶉鸏鸸鰆黂黁鼈龔鲿鸰鸯鸮鸍鹤鸊鸇龔鰈鲿齂鹨鲿鱩 -100 龔鴏鰀鸍龅龂黽黺龥龤麨

黮齜麛鷸鷷鷶鼽鶗鶔 pc 齤齠齩齦齤龥龤鼽黂黁鹅麹龏龌鼄鹀齆 -40 -100 鷈鷅龔麼鶾麙麘麔麑齂鯽鯺齼龔麛齤鸍齆齄齤龅龂齂齁龥龤麨

鷢麘黂黁鹅鷌

齆龡龟鼚鵏麱鸸黂黁鹅鼽齸龂黿齆龀鼟鷢麘鼚鹃鹂鼽龔鹢鼽鸾鼄鹀齜鵈鷌

鸾鸺 id theme.negotiator

鵡鷌 \Drupal\Core\Theme\ThemeNegotiator

齆鼹鼚龏龌鶱鷶鸰鸯鸮鼽鰧麘鯶鯵龔鹢鸖鸕鹟龥龤鰓鰏鲵鲲麨

龥龤鰓鰏鲵鲲鷌

鸾鸺 id access_check.theme

鵡鷌 Drupal\Core\Theme\ThemeAccessCheck

黽黺鲵鲲鯴鯴黿鱭鱩龥龤黿鴏鹤麡麠龔齜齚鶧鰙鸸鹤麡麠鹜鹛齂鯱鸴龅龂麨齜鸸黏齌龔麦麣龏龌齆黕鸄鼚鼄鹀麏鯰鼽鸾鸺齮鯮鯪鹔鰓鰏鲵鲲鷦龌鼪黆鱵鸮鯧鯣鼽鲵鲲麨

本书共88小节:

评论 (写第一个评论)