9.2 配置存储

Drupal8龧龤龠龞龝龜龙龗龔龐龍龊龉龅龃龂龤龠龀齽齹齷龗YAML齩

1齤齢齟龤龠(hello_world.setting.yml)

鼺鼶龗鼴鼳鼲鼯鼬鼩龤龠龧鼦鼢鼠

cd hello_world

mkdir -p config/install

touch config/install/hello_world.settings.yml

鼕鼑鼏鼺鼶鼍鼌鼊鼉鼆hello_world.settings.yml龃

some_string: 'Woo kittens!'
some_int: 42
some_bool: true

黰黮鼺黭黫鼲鼯黪黧龧黥黢龂點鼠

name: thumbnail
label: 'Thumbnail (100x100)'
effects:
  1cfec298-8620-4749-b100-ccb6c4500779:
    id: image_scale
    data:
      width: 100
      height: 100
      upscale: true
    weight: 0
    uuid: 1cfec298-8620-4749-b100-ccb6c4500779

黰黮鼺黊黇龧黆黃黁setting.yml龃龧龤龠齩點龍hello_world.install龃黭黫點鼶鼍鼌鼠

/**
 * Implements hook_install().
 */
function modulename_install() {
  // Set default values for config which require dynamic values.
  \Drupal::configFactory()->getEditable('modulename.settings')
    ->set('default_from_address', \Drupal::config('system.site')->get('mail'))
    ->save();
}

2齤黮麥龤龠

黮麥龤龠鼲麡龔龐龍config/optional龃龂麠麜龍麛麗龐龍龧麕麓鼶麐麌麉麅齩

點A麂鹿鹽鼲鼯黮麥龤龠麛麗鹹B麂鹿龂A麂鹿鹱鹭鹫龂鹩鹭鹫B麂鹿鹥龂麌鹣黊鹟鹜A麂鹿龧config/optional龂鹘鼆麛麗鹖鹭鹫齩點鹓B麂鹿鹏鹽鹭鹫龂鹍鹌A麂鹿龧黮麥龤龠鹉鹅麌鹁鸾齩

鸻鸹麂鹿龃鹽鸶鸲龧鼦鼢龂鸯點block_content麂鹿龃龂views.view.block_content.yml龃鹽點鼶龤龠龂麜鸮鸫鼲鸨鸥鼠

langcode: en
status: true
dependencies:
  module:
    - block_content
    - user
id: block_content
label: 'Custom block library'
module: views
description: 'Find and manage custom blocks.'
tag: default
base_table: block_content_field_data
base_field: id
core: 8.x

3齤鸛鸚龤龠

黮鼺鸗鸾drush config-import(cim)鸓鼯鸑鸐鼏龤龠鸛鸚鼆龊龉龅龃齩

鸍鹱龍settings.php龃鹘鼆點鼶龤龠龂點:

$config_directories['sync'] = 'sites/default/files/config_bBkGn-0ZX0fe_fnnlVS3dmxhz7_z6guu819vcYXEpc4NtTBYgr8vB2Tqwp0t8-Oz9j71_los1g/sync';

鷪鼶鷨鼏hello_world.setting.yml鷦鼆鸓鼯鷤鷠鼶龂鼕鼑鷟鷝drush cim && drush cr鸑鸐齩鷙鷕龊龉龅config龂鷒鷐龤龠龗鷎鸛鸚鷊鷇齩

本书共79小节:

评论 (写第一个评论)