44. 实体Entity(二)配置实体基类

实体Entity(二)配置实体基类

龷龳龰龯龭龫龧龣龢龡龞龝龚龗龔龓龷龳龰龯龝龑龎龭龫龍龊龇龃龰龯龭龫龍龂齾齺龷龳龰龯龝齹齶齴齰龔齭齪龍齦龯龝龷龳龰龯齣齣齟龊龇齜龍齚齙龔齖齒齐龰龯龍齍齉齆齅齂齁鼿鼼鼸龍龫龡龞齙鼴鼰

Drupal\Core\Config\Entity\ConfigEntityBase

龰黿齺龷龳龰龯黽黹鼰

Drupal\Core\Config\Entity\ConfigEntityInterface

黯黽黹龊龇齺龰龯黽黹黮黬黫黧黤龳黽黹鼰

Drupal\Core\Entity\EntityInterface

Drupal\Core\Config\Entity\ThirdPartySettingsInterface

龷龳龰龯龭龫 ConfigEntityBase 黓黑龳黍龷龳黋黇黆龍黮黂麿龰龯龭龫麾齾龣龢麺齹龰龯龫麷龝龭麳龍麱麮麫麨麦麣麠麝鼰

龷龳麜麘鼰

龷龳龰龯鼸麗麔麑齜麏麎龝麜麘龍麌麉麈麏龝麜麘麇黍齜麅鼸麗黓麄麃龍黍龷龳麀鹼龝鹺鹹黆麜麘鹶鹲鹱龧麉鹯麎龝龍齚齙鹬鹫龷龳龰龯龝鹨鹦黓麀鹼龍鹣鹢龷龳龰龯齣齣麏麎黓鹟鹛鹘龷龳龰龯齣齣麜麘齜龝鹬鹫鹖鹕鹨鹦鹒龍鹬鹫鹖鹏麇黍齺龍龷龳龰龯鹋鹇黯黓麀鹼鹆麜麘龣龢黍龷龳麄麃鹂麀鹼黮鸾鸻鸸鸵黓鸲龔龍鸮鸬麉鸩鸮龝麜麘鸥鸣鸟龣鹆

龷龳龰龯鼸麗黍齜龝鸜黇龡龞鸚鸘龝 config_dependencies 鸖黆麔麑麜麘龍麈麜麘龝鸕龎龧齍鸑鸍龫麷鸉龚鼰

鹨鹦 'module', 麮麫 'theme', 龷龳龰龯 'config', 黂麿龰龯 'content'

鷾鷺 config_dependencies 鸖龧龚龗鷹黋龍鸖鷶鷴齍鸑鸍龫麷鸉龚龍鸖鷳鷴鸕鹇龝麜麘鷳龍齙鼴麈鷱鼰

      array(
        'config' => array('user.role.anonymous', 'user.role.authenticated'),
        'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'),
        'module' => array('node', 'user'),
        'theme' => array('seven'),
      );

黬龚鷁鸖鷶鷴麈麜麘鶾龝龫麷龍鶼鸍龫麷鼴鸬麇鶺黓麜麘龝鸕龎鷶龍鼸麗麉鶹龗龍鸕龎鷶鶷鶴鷴鼰

鹨鹦龫麷鼰鸕龎鷶鷴鹨鹦鷶

麮麫龫麷鼰鸕龎鷶鷴麮麫鷶

龷龳龫麷鼰鸕龎鷶鷴龷龳龰龯鸕龎鷶龍齙鶰龧龷龳龰龯黯鷶鶮龃龰龯龝 getConfigDependencyName() 黧鶫

黂麿龫麷鼰龣龢黆麈麉黂麿龫麷龝鶧鶥鶣龧龰龯龍鸕龎鷶鷴黂麿龰龯龫麷 id+ 鶝鼰鶚 + 龰龯 bundle+ 鶝鼰鶚 + 龰龯龝 UUID 龍鸾齉鶮龃龰龯龝 getConfigDependencyName() 黧鶫

黍龷龳龰龯黆麗 $this->dependencies 鶔鶒鸬麇麜麘龍黍鶐鶏黆麔麑龍鶍鶊麾齙鶉龍鶈鶹鶄龚龗鸖鷶鼰 enforced 龍黯鸖鷶鼴龝鷳鶊麾鹱齙鶉龍齜齁鶁鶀鵿龝麜麘龍齰鵽龧鹏鼸黓龃鵻鵺鵷鵳鶐鵲鵮鵭鼴龝麜麘龍麗鵩鵥黧鵢鵠龡龍鶀鵿龝麜麘黍鸬麇龷龳龰龯鵞鹏黓鵚鵖鵺鵷龍鵒鶍鵐鵏黍鶼鵍鸬麇鵞鶣鵉黓鵚鵖鵺鵷龍鵅鵃 $this->dependencies 鶔鶒龝鶊麾齙鼴鼰

      array(
        'config' => array('user.role.anonymous', 'user.role.authenticated'),
        'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'),
        'module' => array('node', 'user'),
        'theme' => array('seven'),
        'enforced'=>array(
                           'config' => array(),
                           'content' => array(),
                           'module' => array(),
                           'theme' => array(),
                            )
      );

龷龳龰龯龔麗鼴黧鶫鶮鵁鴽麜麘鼰

protected function addDependency($type, $name);

鴺鴷鴶龫麷龝麜麘龍 $type 鷴龫麷鷶龍 $name 鷴麜麘鸕龎鷶龍黍龷龳龰龯龭龫黆黓鵚齆龍鸕鶝 core 鶚黮龷龳龰龯麈黍龝鹨鹦鹏鴲鴰鴺鴷

protected function addDependencies(array $dependencies);

鴺鴷鶹龗麜麘龍 $dependencies 龝鸖鷶鷴龫麷鷶龍鸖鷳鷴麜麘鸕龎鷶鷹黋

public function getDependencies();

鴬鴨龷龳龰龯麜麘龍龧鵉 $this->dependencies 黮鶍黆龝 enforced 鸖鴥鴤龝鶊鶰

protected function calculatePluginDependencies(PluginInspectionInterface $instance);

鵺鵷鸜黇龝麜麘龍 $instance 鷴鸜黇龰鴣龍齣齣龧鸜黇鴢黆龝龚龗龰鴣龍鴟鴝黯黧鶫黆鴚龔龝 calculateDependencies 黧鶫黮龷龳龰龯龭龫黆龝鸾鷶黧鶫龧鹏龚齉龝龍鴖黧鶫鷶鴔鸾龍鵐鴓黍鹏鸾黽黹黆龡龞龍鴒鹖鴏鴌龝龧龷龳麜麘鷹鴉龍鵒鴇鹖鴏鴌龷龳龰龯麱鴃

public function calculateDependencies();

鵺鵷龷龳龰龯龝麜麘龍齰鵽黍鸬麇龷龳龰龯鴒鴚龔龍齜鷴龷龳龰龯龝 $this->dependencies 鶔鶒鵚鵖鳿鷳龍鴏鴌龷龳龰龯麱鴃龍鸮鸬鸩鸮龰鵞龝麜麘鸟龣龍鶈鶍黆龝 enforced 鵏龧鹏齟黓鳽鳹龝龍黯黧鶫麌龧鵺鵷麜麘龝齰龔黧鶫龍齜麜鳵鸜黇黮黬黫黧黤龳鶮鳲鳰龍齙鶰麏麎龝麜麘鹏齪齰鹺鷺鳮鳪龍鹣鹢鳨龫麏麎鳤鳣龰黿龍鳟鳜鳙鴚龔鵐龍鳨龫龰黿鵞鸲龔 addDependency($type, $name); 鶮鴺鴷麜麘

齙鶰龷龳龰龯鳖鷴龚龗鳓鳏鹕 (module, theme, or profile) 鹒龝鳎鳌龷龳龍鹣鹢黯龷龳龰龯龝麜麘鹱龧黯鳓鳏龝麜麘龍麏麎齆鳊鳓鳏龝 info 鸘黇

龣龢龡龞齺龚龗鳉鳈龝龷龳龰龯麜麘鸕龎鼰

Drupal\Core\Config\Entity\ConfigEntityDependency

麉麺龗麾鳅鳃鷹鼰龷龳龰龯龝龷龳鸕龎鷶鹂龷龳龰龯黆鳁鲾龝鷹鴉

黯龫齚鲽鲹鲷龍麮麎龔龓鲳鲰鵺鵷龷龳麜麘龍麌麉黫龗黧鶫鼰

public function getDependencies($type) 鼰鴬鴨鴶龫麷龝麜麘

public function hasDependency($type, $name) 鼰鳲鳰龧鲭麉鴶麜麘

public function getConfigDependencyName() 鼰鴬鴨龷龳龰龯龝龷龳鸕龎鷶

龷龳麜麘龝鲬黧鸘鲩鲨鲧鼰

https://www.drupal.org/docs/8/api/configuration-api/configuration-entit…

龷龳麜麘鷶鼰

getConfigDependencyName() 鴬鴨龝龧龷龳麜麘鷶龍鹱鹋龧龷龳龰龯龝龷龳鸕龎鷶龍黮鲹鲷龷龳鸕龎龝龷龳鸕龎鷶龧龢龚龝鹆

鲜鵢鷴鼰龷龳鴒鲛 + . + 龷龳 id

龷龳鴒鲛鷴鼰鹨鹦鷶 + . + 龷龳龰龯鸚鸘黆龡龞龝 config_prefix

齙鶰鲖麉龡龞 config_prefix 鶴麗鸚鸘黆龝鸜黇 id 齁鲔

鸜黇鴢鼰

黍龷龳龰龯龭龫黆鶹鵍鲑鲎鴨鸜黇鴢龝鲊鳖龍鹱鹋龧 EntityWithPluginCollectionInterface 黽黹龍鸟龓鸜黇鴢鹶鹲齙鼴鼰

黍鲆鶹鲄鲃鼴龣龢黆龚龗鸜黇龫麌龰鴣鲁鶄龚龗龰鴣鸕龎龍鶈龚鲀鼸龷龳龝鸜黇龫麷龍鱿鴉鹏鸾龷龳麏麎鱻鱹鹏鸾龰鴣龍齚齙鹦鸜黇龍鹦鼸齪齟鶄黿黍鱶鱲黆鶹龗鲨黧龍鶼龗龰鴣鶣麉龃鱮龝龷龳龍鹏鸾鱫麫鹂黂麿鱧鱧龍龣龢鱥鲆鱤鴽鱠鱝鸕鹏鸾龷龳鷴鸾龚龗鸜黇龫鱜鱙鶹龗龰鴣龍鱕鷺鱻鱹齺鶝鸜黇鴢 PluginCollection 鶚齍龗鹶鹲龍鷴齺黮鴢鱓鱲鶹龗鸜黇鱐鱎龍鸜黇龣龢鸲龔鸜黇鴢 Plugin collections 鸕龎鶮鱤鴽鶹龗龰鴣龍龣龢黋黇黆鹬鹫齺龚龗鸜黇鴢鸕龎龝龑龎龭龫鼰

\Drupal\Component\Plugin\LazyPluginCollection

黍鱆鱂黆鹬鹫齺龚龗鳎鳌龰黿鼰

Drupal\Core\Plugin\DefaultLazyPluginCollection

鳎鳌龰黿龝鸜黇鴢鸕龎龝麾鳅鰾鷹黽鰺麺龗鳃鷹鼰

鸜黇鱤鴽鰹鼰龔鶮龰鴣鲁鸜黇龍龰鴣鲁鵞鰷鳊龷龳鶧鶥龍鶍龰鸜黇鱤鴽鰹龰黿齺鸜黇鰶鰴黽黹龍龣龢黆麈麉龝鸜黇鶣龧鼸麗鰷鳊龷龳鶧鶥龝

龷龳鶧鶥鼰鴢鱓麈麉鸜黇龝龷龳鶧鶥龍龧龚龗鷹黋龍鸖鷶鵉鰲鷴鸜黇龝龰鴣 id

鰯鴓鼸麗鰫鴨麗鶉鸜黇鴢龫黆鶣麉鶝 Lazy 鶚鰩齉龍齜龧鰦鹢鴝鰥鰣鰡齜齁鶁鰠鰞龰鴣鲁龍鸜黇鴢鸕龎黆鸬麇齺麈麉鸜黇龝龷龳鶧鶥龍鰚麏麎鴶龗鸜黇鵞麅麜鴉龷龳鶧鶥龰鴣鲁齜龍鵒鹏龧鰙鶉鰘齶鶣龰鴣鲁齺龍齍龧鱕龓鶒齪鰔鷾龍齜黮麿鰹龫鰒龍麌麉麏麎鵞麅龰鴣鲁鹆

龣龢鰎龰黿齺龚龗鶐鵲龝鸜黇鴢鸕龎鼰

Drupal\Core\Plugin\DefaultSingleLazyPluginCollection

龚鰍鶮鰊鸜黇鴢鱓鱲齟鱤鴽鶹龗鸜黇龍鶈麉鵞麌麏麎龚龗鵞鶴鸲龔黯鸕龎龍齜麌鱤鴽龚龗鸜黇龍齍龧鱕龓鰠鰞龰鴣鲁鰆鶮龝鶒齪鰂鰁鵳鶍鵐鯾龝鹆

龣龢鷴麏麎龔鴨鸜黇鴢龝鸕龎龡龞齺龚龗黽黹鼰

Drupal\Core\Plugin\ObjectWithPluginCollectionInterface

鱓鱲麌麉龚龗黧鶫鼰

public function getPluginCollections();

鴟鴝 Collection 龧鯴鷹鯱鵢龍黯黧鶫鴝鷴鴬鴨鶹龗鸜黇鴢龍鶹龗龧鰦鹢鴝鰥鰣鰡鲷龗鸜黇鴢鸕龎鱓鱲鼸麗鱤鴽鶹龗鸜黇龍鶈鰚鸜黇麏麎麗鴶鸍黧鵢齴龫鵞龍鹋鼸麗鵉鶼龚龫鸜黇鯮鷴龚龗鴢龍鱕鷺鯱齾鶹龗鸜黇鴢龍齍鰆鶮鯬鶹龝鯨鯧鶒龍齚齙鹦鸜黇黆龍鼸麗鵉鼸鯣龝鹦黮鹏鼸鯣龝鹦齴鯢黑黍麺龗鴢鱓鱲龍齍鹋龧鶹龗鸜黇鴢龝鱕鶮龍黯黧鶫鴏鴌龚龗鷹黋龍鸖鷶鷴鶁鷱鸜黇齴龫龝鶔鶒鷶龍鸖鷳鷴黯齴龫鼴龝鸜黇鴢鸕龎鹆

龷龳龰龯 id:

龷龳龰龯龝 id 龧龚龗鰘鯞鯜龚龝鰩鯚鯗龍鰩鯚鯗 ’0’ 鵳鯓鰩鯚鯗龧鯏鯌龝 id

龷龳麄麃鯉麀鹼鼰

龷龳龝麄麃黮麀鹼鹏龧龚龗鲹鲷龝鹺鹹龍齟鸾鸻鵁鴽麜麘鸟龣龍鼸齪齟鳹鵻鶍鵐黋黇龍鷾鷺齍龚鹺鹹龧麏麎鵞鸵龝龍鷴鷺龣龢黍龷龳龰龯龭龫黆黤龳齺麺龗鶔鶒鼰

$isSyncing 鼰鯅鯄鷳龍鶁麑龷龳龰龯黍鯃鳊鹺鹹黆龧鲭鵁龓鱜鱙鹂鯬鵖鵳鹟鹛鯂鵥

$isUninstalling 鼰鯅鯄鷳龍黍麀鹼鹺鹹黆龍鶁麑龷龳龰龯龧鲭鵁龓鸩黍鹟鹛龝鯂鵥

鸟龓龷龳麄麃鹂麀鹼鹂鯃鳊鹂鯃鶄麱龣鮾齟麉龚龗鳉鳈麮麫鶮鮼鮹鹆

龷龳鮵鮳鼰

黮鲹鲷龷龳鸕龎龚齉龍龷龳龰龯鹱麉鮵鮳鶔鶒龍龔 $langcode 鮯麇鮵鮳齁鼿龍鳎鳌鷴鮭鮵

黬黫黧龷龳黤龳鼰

龷龳龰龯黽黹龧龊龇齺黬黫黧黤龳黽黹鼰

Drupal\Core\Config\Entity\ThirdPartySettingsInterface

鷾鷺龷龳龰龯龭龫龰黿齺黬黫黧黤龳鮩鳣鶧鶥龝齭齪龍麈鮨黬黫黧龧鵠麏麎黍龷龳龰龯鱓鱲鮯麇黮鶍鮧鮣鮢鴥龝鶧鶥龝鹨鹦龍齍鲀鶧鶥黍龷龳龰龯黆龔 $third_party_settings 鶔鶒鮯麇龍鸖鷶鷴鹨鹦鷶龍鷳鷴龚龗鸖鷳鸕鷹黋龍龧鹨鹦麏麎龝鶧鶥鹆

龷龳龰龯黮黂麿龰龯鸵龝鹏鸾鼰

黍鵖鱙龝龰龯黆龷龳龰龯麉 id 龍鵒黂麿龰龯鲖麉龍鯣鼰 https://www.drupal.org/node/2478811

龷龳龰龯黆龝龷龳鶧鶥鯃鶄鴨鷹黋鼰

鼸麗黍龷龳龰龯龫鸚鸘黆鵠龡 config_export 鶮鰊麑麏麎鯃鶄鹣鲀龷龳鵏龍齍鲀鵏齟黮麗鼴鵏鴥鴤鼰

        [ 
          'uuid' => 'uuid',
          'langcode' => 'langcode',
          'status' => 'status',
          'dependencies' => 'dependencies',
          'third_party_settings' => 'third_party_settings',
          '_core' => '_core',
        ];

齍齉龝鴥鴤鲊鳖黆 config_export 鵠龡龝鵏鰂鮝鷁鯬鮚龍黯鷹黋黆鸖鷶龧龷龳鵏龝鶔鶒鷶龍鸖鷳龧鯃鶄龝龷龳鷹黋黆鸕鹇龝鵖鸖鷶龍齙鶰鸚鸘黆鲖麉鵠龡 config_export 鸖龍鹣鹢齟鮖鮔鸕鹇龷龳鸕龎龝龫麷鲁 Schema 龡龞黆 mapping 鶔鶒龝鸖鷶鳖鷴麏麎鯃鶄龝鵏龍黯龷龳鸕龎鷶鷴鼰龷龳龰龯龝龷龳鴒鲛 + 鮓鮑 + 龷龳 id 龍鹹鸣齁鼿鷴鼰

$entity_type->getConfigPrefix() . '.' . $this->id()

鸬麇鴒鲊鳖鼰

齙鶰龷龳龰龯龰黿齺鸜黇鴢黽黹鼰

Drupal\Core\Entity\EntityWithPluginCollectionInterface

鹣鹢鸬麇鸜黇鴢龝龷龳鶧鶥鹆鮐鹛龷龳龰龯龝 uuid 鮌鮈鹆鸮鸬鮅鮄麇黍龝龷龳龰龯 uuid 鹏黓鳹鮃鹆鰚龷龳龰龯鹏鵁龓鸾鸻鯂鵥鵞龍鵺鵷龷龳麜麘

鮀麇鱫魿鼰

龷龳龰龯龝齰龔鮀麇鱫魿鹏鸾龓黂麿龰龯鹕鱫魿鷶鷴鼰龰龯龫麷 id+ 鶝鼰鶚 + 龰龯 id 鹒龍鵒龧鼰

config:+ 龷龳麜麘鷶鶚龍鶍黆龷龳麜麘鷶鷴鼰龷龳鴒鲛 + . + 龷龳 id

鸬麇黮鹟鹛鵞麌魻鯌鮾鶁鱫魿龍龃鴃鱫魿龝魻鯌黍龷龳龣龢鱓鱲鮅鮄鴲鴰齺

本书共63小节:

评论 (写第一个评论)