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

评论 (写第一个评论)