4

I try to import specific configuration. I use this :

$config_path = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
$source = new FileStorage($config_path);

$config_storage = \Drupal::service('config.storage');
$config_factory = \Drupal::configFactory();
$uuid_service = \Drupal::service('uuid');

$configs = [
  'field.storage.config_pages.field_areas',
  'field.field.config_pages.configuration_implantation_page.field_areas',
  'core.entity_form_display.config_pages.configuration_implantation_page.default',
  'core.entity_view_display.config_pages.configuration_implantation_page.default',
];

$config_storage->write('field.storage.config_pages.field_areas', $source->read('field.storage.config_pages.field_areas'));
$config_storage->write('field.field.config_pages.configuration_implantation_page.field_areas', $source->read('field.field.config_pages.configuration_implantation_page.field_areas'));
$config_storage->write('core.entity_form_display.config_pages.configuration_implantation_page.default', $source->read('core.entity_form_display.config_pages.configuration_implantation_page.default'));
$config_storage->write('core.entity_view_display.config_pages.configuration_implantation_page.default', $source->read('core.entity_view_display.config_pages.configuration_implantation_page.default'));

If the field is created, the table is not created.

How to create the tables associated?

4
  • I believe the system will create the table when you first try to save some data to it
    – Clive
    Sep 27, 2019 at 9:24
  • Try to add $config_storage->save();
    – berramou
    Sep 27, 2019 at 9:54
  • 1
    Take a look metaltoad.com/blog/…
    – berramou
    Sep 27, 2019 at 9:55
  • @berramou, post this as an answer. The important thing is not simply store config, but create and save config entities and so run CRUD methods/hooks like FieldStorageConfig::preSave
    – 4uk4
    Sep 27, 2019 at 12:00

1 Answer 1

2

You should save the config like $config_storage->save(); :
As @4K4 mentioned :

The important thing is not simply store config, but create and save config entities and so run CRUD methods/hooks like https://api.drupal.org/api/drupal/core%21modules%21field%21src%21Entity%21FieldStorageConfig.php/function/FieldStorageConfig%3A%3ApreSave/8.7.x

1
  • Getting Call to undefined method Drupal\Core\Config\CachedStorage::save() error when I try to use $config_storage->save()
    – Ahmad
    Sep 29, 2020 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.