73. 主题处理器theme_handler

龺龷龶龲龮 theme_handler 龗龺龷龕龲龮 theme.manager 龎龍龊龇龅龁齽齻齺齹齸齴齲齯齮齪齨齤齣齠齝齜齚齖齓齹龺龷龕龲龮齒齎龺龷齌齈齆齃齀龺龷鼽鼺鼸鼶齹鼲龺龷龶龲龮齜鼱鼭鼬鼨鼥齽鼤鼢齹鼡鼠鼬龺龷龕龲龮鼟鼝鼛鼚龮鼖鼔龺龷鼐鼎鼌鼊龅龁鼉鼈齠齝鼆鼃齹鼁鼀黾黼黺

齻齺 id theme_handler

黷黺 Drupal\Core\Extension\ThemeHandler

黕黔黐黍黺 \Drupal::service("theme_handler");

龺麵齜鼱齽鼤鼢龍麴麱麰麯麭鼊龊龇麪齽龺龷麧麣鼟龲麢麠麝鼎龊鼟麛麘龺龷 info 麭鼊齽麕麔麓鼟鼝鼛鼚齲麏齚麎麍麋齽麇麅麄麀鹿鼟鹻鹸龺龷龍鹵鹴鹱鹭鹬鹩 UI 麪鼖鼖鹣

龺龷龶龲龮龺麵鼤鼢龍鼡鼠鼥鹴齒龅龁龺龷齽麧麣鹢鹞鹛鹱鹢鹞鹚黼鹘齹鼠鼥鼌鼊鹔鹐麧麣鹢鹞鹌鹋鹈鹅鹄鼢龺龷鹐鹀

龺龷鼐鼎鸼齯黺

鹅黼龍齲麏齆龺龷鼐鼎齽鸼齯鸸鸴鸰鼀黺

鸭龮鸼黺

鸬鸪龺龷麧麣鸼齹齚麎鸩齲齹龍鸥鸢龺龷齽鸩齲鸟鸥齹鸛鸙齎 info 麭鼊齽麭鼊鸼齹黾鸕 bartik.info.yml 鸎鸍鸉鸭龮鸼鹋龍鸕 bartik 鸎齹齖齝鸈鸰鸅鸂齹鷿鷻鼬黺 /^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/ 齹鹔麏鷗鼁鸼齯齸齴鷓鷒鹱鷿鷻齹齨齖齝鷑鷐齒齹黾鸕 template 鸎鹣黼麭麪鷍鷌鷗鸢鷋鹸齹鷊龅鷈龺龷鸼鷅鷃鷀鸭龮鸼鹀

鶿黷鹈鶽鸼黺

info 麭鼊麪 name 麓鷀鼁齽鸼鶼齹鶹鹈鹅齆鸭龮鸼齖齓鶷鹈齖齓齹鹭鹬鹩 UI 麪齹齝鸈鶴鸅鸂

鶳鶰鸼黺

鶬鶩龺龷鼐鼎麭鼊齽鶳鶰鸼鶼齹鶥鶤黺龺龷齽麴麱麰麯鶣鶟鼠龍鹩麰麯鶜鶙鷓鷒麵鶘齽鹅鸕 .info.yml 鸎鹌鶕鶔鶑齽麭鼊鹛鶜鶙麪鶍鶌鹔 type 鶋鶉鹘齹鼲齖龍鶆鶃鶳鶰鶔鶀鵼鵺齹鵹鵶龺龷齽鶳鶰鸼鹈鹅齆鸭龮鸼齖齓齹齨鵴鵳鶣鵯鹴鹱鼐齓齹鶳鶰鵬鵪龗鶔鶀齖鵩齹鶳鶰鸼齖齝鷐齒黺 'src','lib','vendor','assets','css','files','images','js','misc','templates','includes','fixtures','Drupal',

鶹麏鶳鶰鹩鷑麴麱鷅鵜鷑鵘鵖鹛鹈鹅鵕齒鶹鵓鷗鶉鵏鵋鵉鵅齽龺龷齹齖鵜鹢龊龇鵄鼱鵀鴽鴼鴸鹘

龺麧麣麭鼊鸼黺

麕麔鼬鸕鸭龮鸼 . 麧麣黷鴴鸎齹黾鸕 bartik.theme 鸎鼟鸕 search.module 鸎齹龺麧麣麭鼊齖龍鶍鶌齽齹齒齎鶬鶩鴱鴮鴫龺龷鴩麵齽麍麋鴫鼁鼀鴥麀齹鴢齎麧麣鴟鶳鶰齹龍齲鴜 php 麭鼊齹齨鴛齖鹅 php 鴗麭鼊鸼鹌鶕齹黾鴓鶬鹩鷻鷑麕麔麘鴒鹀鴐鴏龺龷龍齲鴜鷗鴍鴉鴇齹鴆鸼鼬鸕鴐鴏鸼 .engine 鸎齹黾鸕 twig.engine 鸎鹀

麧麣鹢鹞黺

鷊麴麱鷈齲鴜鳾黍齽麧麣鷅齹龊龇鵜鼝鼛鼚齲鴜麧麣鹢鹞黺

\Drupal\Core\Extension\Extension

鹱鹢鹞齸齴鹩黷鼁鼀麪鳻鹔鳺鳸齽鶋鶉齹齨鳷鹩鼝鼛鼚鹌鳵鹢鹞鳱鳰鳯鹿鹐鳫鵉鶋鶉齹鹚黼齹鶹麏鶋鶉龍鳪鳧齽鹛 public 鹘齹鹱鹢鹞鳣鳡鹐麧麣鳟鳝齽鳜鹔鵼鵺齹齤龍龺龷鵼鵺齽麝鴒鳘齹鼝鼛鼚鷅黺

$theme = new Extension($root, $type, $pathname, $filename);

鳔鴜鳓麋鳑鸢龍黺

$root drupal 鴟鳎鳍齹黾鸕 C:\root\drupal 鸎鳋鹔鹌鶕鳇鳆鳃

$type 黺麧麣黷鴴齹鸛鳁 info 麭鼊鳀鲽齽 type 鹿

$pathname info 麭鼊鼐鹢龊龇鴟鶳鶰齽鼐鹢鳎鳍齹黾鸕 core/themes/bartik/bartik.info.yml

$filename 黺龺麧麣麭鼊鸼齹鹚鲺麭麱鲶齹黾鸕 bartik.theme 鸎齹鶥鶤鴛鷌 info 麭鼊齽麭鼊鸼

鹩龺龷麧麣麪鴥齒齽麧麣鹢鹞鶋鶉黾黼鹛鶹鳀鹅 $theme 鷀鲳麧麣鹢鹞鹘黺

$theme->type 黺麧麣黷鴴齹龺龷龍鸕 theme

$theme->info 黺鳵 info 麭鼊鳀鲽鲭鲩鲦鸛齽鶜鶙齹鲣麘鹐麕麔鹿

$theme->engine 黺鹱龺龷鷐齒齽鴱鲡鴐鴏齹麕麔鼬鸕 Twig

$theme->base_theme 黺鲟鲝鼉龺龷齽鸭龮鸼

$theme->libraries info 麭鼊麪鲙鹸齽鲖

$theme->status 黺鲕鹬龺龷龍鹵鷑鲒鲎齹鲌麋鹿齹 1 鼬鲒鲎齹 0 鼬鲉鲒鲎

$theme->owner 黺鳜齒鴐鴏齽龺麧麣鸼齹鲇鴥鹿鼬黺鸕 core/themes/engines/twig/twig.engine

$theme->prefix 黺鳜齒鴐鴏鲺鶕齹鲇鴥鼬鸕 twig

$theme->base_themes 黺龍齲鴜麋鼌齹 鲄鸼龍鼉龺龷鸭龮鸼 齹鲄鹿鼬鼉龺龷齽鶿黷鹈鶽鸼齹黾鴓鷀鼁鹐鼉龺龷齨鸴齖鶬鹩齹鸍鸉鹿鼬 NULL 齹鱽鱼麢鱸鲳鲕麠麝麢鱸齹鱵齲鴜鱽鱼龍鴟鼉龺龷齹鵴鹌齲鴜鱽鱼龍鲟鲝鼉龺龷

$theme->base_theme 黺龍齲鴜齯鱳鱰鹿齹鲟鲝鼉龺龷鸭龮鸼齹黾鴓鳋鹔鼉龺龷鷻鹱鶋鶉齖鶬鹩

$theme->sub_themes 黺龍齲鴜麋鼌齹鲳鲕鳜鹔鼶龺龷齹鲄鸼龍鼶龺龷鸭龮鸼齹鲄鹿鼬鼶龺龷鶿黷鹈鶽鸼齹鱽鱼麢鱸鳋鹔鶤鼀

$theme->required_by 黺麋鼌齹鱽鱼鼬齚鳰鴩麵鹱龺龷齽龺龷鹛鼶龺龷鹘

$theme->requires 黺麋鼌齹鹱龺龷鴩麵齽龺龷鹛鼉龺龷鹘

$theme->origin 黺鶜鳰鼬鱨鱸鶳齽鷐齒齹齒齎鱧鱤麧麣麴麱齽鱠鼛鶳鶰

$theme->subpath 黺鶜鳰鼬鱨鱸鶳齽鷐齒齹麘鼠 $theme->origin 鹋龍鼐鹢齎龊龇鴟鶳鶰齽鼶鶳鶰

$theme->sort 黺鹭鹬龺龷鷅齽鱨鱸鹿

$theme->root 黺龊龇鴟鳎鳍齹黾鸕 C:\root\drupal

$theme->pathname info 麭鼊鼐鹢龊龇鴟鶳鶰齽鼐鹢鳎鳍齹黾鸕 core/themes/bartik/bartik.info.yml

$theme->$filename 黺龺麧麣麭鼊鸼齹鹿黾鸕 bartik.theme 鸎齹鶥鶤鴛鷌 info 麭鼊齽麭鼊鸼

鹱麧麣鹢鹞麪齹鷍黷鼁鼀齽黐黍鳱齹鱝鹈鹅鱚齒 info 麭鼊鼝鼛鼚齽 \SplFileInfo 鹢鹞鼠齽黐黍

黼麭龅鷈麧麣鹢鹞鷅鷃龍鷀鹱鹢鹞鹀

龺龷鼎鲄鱏鱌麓龗鱉麅鹿黺

鹩鹐鲭龺龷龶龲龮鲺鱇齣鹴鹱鱄鱀鰽齆龺龷鼐鼎齽龺麵鱏鱌齆鵼鵺鰼鶬鹀

\Drupal::service("config.factory")->get('system.theme')->get(鸕admin鸎);

鰼鶬鹌鰸龕龲龺龷齽鸭龮鸼

\Drupal::service("config.factory")->get('system.theme')->get(鸕default鸎);

鰼鶬鲺鰶麕麔龺龷齽鸭龮鸼

\Drupal::service("config.factory")->get('core.extension')->get('theme');

鰼鶬鳜鹔鷑鲒鲎齽龺龷齹麋鼌鹿齹鲄鸼鼬龺龷鸭龮鸼齹鲄鹿鼬 0

\Drupal::state()->get("system.theme.data");

鰼鶬鳜鹔鷑鲒鲎齽龺龷齹麋鼌鹿齹鲄鸼鼬龺龷鸭龮鸼齹鲄鹿鼬鹢鹴齽麧麣鹢鹞

\Drupal::state()->get("system.theme.files");

鰼鶬龊龇鳜鹔龺龷齽 info 麭鼊鳎鳍齹鸈鶴鳋鹔鰴齒齽龺龷齹麋鼌鹿齹鲄鸼鼬鸭龮鸼齹鲄鹿鼬鼐鹢龊龇鴟鶳鶰齽鳎鳍齹黾黺 core/themes/bartik/bartik.info.yml

\Drupal::state()->get("system.theme_engine.files");

齓鼠齹鳻龍鰼鶬鴱鲡鴐鴏龺龷齽鸭龮鸼齆鳎鳍齹麕麔鼬 [twig=> core/themes/engines/twig/twig.info.yml ]

\Drupal::cache('bootstrap')->get('system_list')

鰭鶬龺龷麋鶃齹鹿鼬鰬鴜鱽鱼齽麋鼌齹鲄鸼 theme 齽鹿鼬 \Drupal::state()->get("system.theme.data") 齽鶜鶙齹鲄鸼 filepaths 齽鹿鼬鵉鴜 ['type' => 'theme','name' => ‘龺龷鸭龮鸼’ ,'filepath' => info 麭鼊鳎鳍鸎 ,] 鱽鱼鶀鼱齽麋鼌齹黾黺 ['type' => 'theme','name' => bartik ,'filepath' => 鸕core/themes/bartik/bartik.info.yml鸎,]

龺龷龶龲龮黐黍鰩鲶黺

\Drupal::service("theme_handler")->getDefault();

鰥鷈鲺鰶龺龷鸭龮鸼

setDefault($name);

鰢鱌鲺鰶龺龷齹鳓麋鼬鸭龮鸼齹鶍鶌龍鰞鰚鲒鲎鵖齽龺龷齹齤齖鵜鰙鰘黾鴽鰭鶬齹鳜鹅鹱黐黍鳻鹴鹱龊龇鷐齒鶜鳰鷐齒

listInfo()

鰖鲦鳜鹔鰞鰚鲒鲎齽龺龷齹鰔鰐麋鼌鹿齹鲄鸼鼬龺龷鸭龮鸼齹鲄鹿鼬鹢鹴齽麧麣鹢鹞齹鹅麧麣鶳鶰鸼鼢鼬鱨鱸鶆鶃鹛鹚 \Drupal\Core\Extension\ExtensionDiscovery::sort 鹘齹鹩鳺鵉鷐齒鴉鴇黼鶹鴜麢鱸龍鰎鶤鼀齽

addTheme(Extension $theme)

麛麘齲鴜麧麣鹢鹞鷈鰞鲒鲎龺龷鰖鲕

refreshInfo()

鰌鰊麴麱麭鼊龊龇齹鰌鰊鶀鰈鰞鰚鲒鲎龺龷鰖鲕

rebuildThemeData()

麴麱麭鼊龊龇齹鰔鰐鳜鹔鶬鹩齽龺龷齹鸈鶴鲉鲒鲎齽龺龷齹龲麢龺龷齽麠麝鼎龊鹅鸸鰢鱌鼐鼎鶋鶉麄麀齹鰔鰐齲鴜麋鼌齹鲄鸼鼬龺龷鸭龮鸼齹鲄鹿鼬鹢鹴齽麧麣鹢鹞鹀

getBaseThemes(array $themes, $theme)

鹩齲鴜龺龷鰁麪麰麯齲鴜龺龷齽鳜鹔鼉龺龷齹鰔鰐齲鴜麋鼌齹鲄鸼龍鼉龺龷鸭龮鸼齹鲄鹿鼬鼉龺龷齽鶿黷鹈鶽鸼齹黾鴓鷀鼁鹐鼉龺龷齨鸴齖鶬鹩齹鸍鸉鹿鼬 NULL 齹鱽鱼麢鱸鲳鲕麠麝麢鱸齹鱵齲鴜鱽鱼龍鴟鼉龺龷齹鵴鹌齲鴜鱽鱼龍鲟鲝鼉龺龷鹀

getName($theme)

鴟鶃齲鴜龺龷齽鸭龮鸼鰔鰐鶿黷鹈鶽鸼

getThemeDirectories()

鰥鷈鳜鹔鰞鰚鲒鲎龺龷齽鰀鹢鳎鳍齹鰔鰐麋鼌齹鲄鸼鼬鸭龮鸼齹鲄鹿鼬鳎鳍鸼鹛齖鳡麭鼊鸼鹘齹黾黺 C:\root\drupal/core/themes/bartik

themeExists($theme)

鹻鯼龺龷龍鹵鶬鹩齎鰞鲒鲎龺龷麪

getTheme($name)

鲇鵖龺龷鸭龮鸼黔鰥麧麣鹢鹞

hasUi($name)

鹻鯼龺龷龍鹵鹴鹱鹩 ui 麪鲦鯹齹黾鴓 info 鵼鵺麪 'hidden' 鼬鯷齹鸍鸉齖鲦鯹齹黾鴓鯵鯴鹱麓鰢鱌齹麕麔鲦鯹齹黾鴓龍麕麔齽龕龲龺龷鴫鲺鰶龺龷齹鸍鸉鯲鯰鲦鯹

鵶鳱鲒鲎鯮鴒黐黍齸齴鹩 8.x 鯧鳟麪鶬鹩齹齨鯦齖鹴鹱鷐齒齹鯢鹩 9.0 鯧鳟麪鯡鷍齹鷐齒鲒鲎齻齺鲳鯝

龺龷 info 麭鼊齽鲣麘麕麔鹿黺

龺龷 info 麭鼊鷑龊龇鶽黔鷅鵜鲣麘麕麔鹿齹鯙齒麋鼌鸕 + 鸎鹄鼢齹鯕鵶鹈鹚鹩鳋鹔鷀鼁鯑麓鷅齤鵜龍鯎鸉鯌鼶齹麕麔鹿鷑鼁鼀鹩龺龷龶龲龮麪齹黾黼黺

$defaults = [
      'engine' => 'twig',
      'base theme' => 'stable',
      'regions' => [
        'sidebar_first' => 'Left sidebar',
        'sidebar_second' => 'Right sidebar',
        'content' => 'Content',
        'header' => 'Header',
        'primary_menu' => 'Primary menu',
        'secondary_menu' => 'Secondary menu',
        'footer' => 'Footer',
        'highlighted' => 'Highlighted',
        'help' => 'Help',
        'page_top' => 'Page top',
        'page_bottom' => 'Page bottom',
        'breadcrumb' => 'Breadcrumb',
      ],
      'description' => '',
      'features' =>  [
                   'favicon',
                   'logo',
                   'node_user_picture',
                   'comment_user_picture',
                   'comment_user_verification',
  ],
      'screenshot' => 'screenshot.png',
      'php' => DRUPAL_MINIMUM_PHP,
      'libraries' => [],
];

鯕齎鯙齒麋鼌鹌鲣麘鹄鼢齹鳜鹅鷊齖鯃麵鯀麕麔鹿鷅齹鴩麵鳁鼁鼀鹱鹿齹鮾黾齖鯃麵鼉龺龷鸍鸉鴩麵鹸鮻鼁鼀鼬 FALSE 齹鹵鷻麕麔鼬 'stable' 龺龷鹀

麕麔鹿鷑鲣麘鹌齹鵜齃齀 system_info 鼽鼺鼸黺

$moduleHandler->alter('system_info', $theme->info, $theme, $type);

鶹鳀 $theme 龍鲺麭龅鷈齽 \Drupal\Core\Extension\Extension 鹢鹞 info 龍鹢鹞鳱鲣麘齽鳪鳧鶋鶉齹鶜鶙龍鹴齒鹐麕麔鹿齽 info 麭鼊鶜鶙麋鼌齹 $type 鹿鼬 'theme' 齹鴱鴮鹈鹅鲇鵖 hook_system_info_alter() 鮹鼽鼺齤齹鲝鮸鮵鴜鳓麋齹鱵齲鴜齆鱵鮵鴜鳓麋鶣鶟鼠龍鸈鸰鹩 Extension 鹢鹞麪齽齹鯕齎 php 鹢鹞麕麔龍鮱鴐齒鮭鮬鳜鹅鴱鴮鹈鹅鼽鼺鹱鹢鹞鹛鼽鼺 $info 麋鼌鳓麋鯢鰎鼢齒齹齤齖龍鴐齒鮭鮬鹘齹鯕齎齃齀鼸鼶齽鮩鵹齹鶤鮧鮤鱄鲒鲎齽鴱鴮鹈鹅鼽鼺鹌鲽鷿鹩鲒鲎龺龷齽 info 麭鼊

龺龷齽麠麝黺

鹈鹅齲鼥齲鼥齽麠麝黼鮹齹鼥麋齖鵩齹齨鳻鹔齲鴜鲟鲝鼉龺龷鹛鮠龺龷鹘齹鶷鹋龍鸕鮟鼉鵉鼥麠麝鸎齹鶹齆 php 黷麠麝黷鮛鹀

drupal 龍鹈鹅鷐齒鵉鴜龺龷鴐鴏齽齹黾鴓鹩龺龷麠麝鮗麪齹鼶龺龷齆鼉龺龷鷀鼁鹐齖齓齽龺龷鴐鴏齹鸍鸉鯢鹅鴟鼉龺龷齽鰢鱌鼬鮖鹀

鷊鲙鹸鹐鼉龺龷鹌齹鹋鳁鮓鲙鹸鹐鼉龺龷鶆鮒齹鹩 info 麭鼊麪齖鶍鮑鮓鷀鼁

鮎鮋黺

  1. info 麭鼊鳀鲽鶥鶤鸅鸂齽鮇龷齹黾鸕 'base theme' 鸎麓鮆鼱鹐鸕 'base theme' 鸎鯢鰙鮹鼢齒齹鸍鴼鴸鹐麋鼌鲄鸼齹鹩鰈鮂 info 麭鼊鷅鵴魿魾鯰鼽鼺齹魻魺鶹麏魶鮇龷鹀
  2. 鹩龺龷龶龲龮麪鷐齒鹐齲麏魴魰魮魭麘魫龊龇鶉齝齹黾黺鼬龺龷鼝鼛鼚 drupal_get_filename 齚麎麍麋齹鲇鵖 drupal_static 麍麋鰢鱌麪魧麇麅鶋鶉鼖齹鹔魤魢鹈鹅鳁魠鵬魝

本书共88小节:

评论 (写第一个评论)