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小节:

评论 (写第一个评论)