How to set/ delete array variables in .yml file using config factory?

by Tejas Vaidya   Last Updated May 16, 2018 14:07 PM

File below is installed successfully when I install the module 'abc'.


abc/config/install/abc_custom.yml

langcode: en
status: true
dependencies:
  config:
    - field.storage.node.body
    - field.storage.node.field_contact
    - field.storage.node.field_department
  module:
    - node
    - text
    - user
id: abc
label: 'ABC List'
.
.
.

I want to update this config when I install/ uninstall second module 'efg'. On install add one config and module. On uninstall remove the same one config and module and other variables should remain as before.


langcode: en
status: true
dependencies:
  config:
    - field.storage.node.body
    - field.storage.node.field_contact
    - field.storage.node.field_department
    - another.custom.file
  module:
    - node
    - text
    - user
    - another_module
id: abc
label: 'ABC List 2'
.
.
.

efg/efg.install

function efg_install() {
   \Drupal::configFactory()
    ->getEditable('abc_custom')
    ->set('label', 'ABC List 2') //(This works)
    ->set('dependencies', [ //(This part doesn't seem to work for appending)
      'config' => [
        'another.custom.file',
      ],
    ])
    ->save(TRUE);
}
function efg_uninstall() {
   \Drupal::configFactory()
    ->getEditable('abc_custom')
    ->set('label', 'ABC List') //(This works)
    ->clear('dependencies.config.another.custom.file') //(Not working)
    ->save(TRUE);
}

In above code 'label' works but 'dependencies' only shows 'another.custom.file' in array. How do I use config factory to add more dependencies in previous config?

Thanks in advance.



Related Questions


Using Configuration API in drupal 8

Updated June 15, 2015 23:03 PM




Config folder in drupal8

Updated April 13, 2016 08:03 AM