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

评论 (写第一个评论)