You are here

function opigno_course_update_8002 in Opigno course 8

Update configs in opigno_course.

File

./opigno_course.install, line 24
Install, update and uninstall functions for the Opigno Course module.

Code

function opigno_course_update_8002() {
  $config_path = drupal_get_path('module', 'opigno_course') . '/config/install';
  $storage = new FileStorage($config_path);

  // Install new field.
  $data = $storage
    ->read('field.storage.group.field_course_media_image');
  if (!FieldStorageConfig::loadByName($data['entity_type'], $data['field_name'])) {
    FieldStorageConfig::create($data)
      ->save();
  }
  $data = $storage
    ->read('field.field.group.opigno_course.field_course_media_image');
  if (!FieldConfig::loadByName($data['entity_type'], $data['bundle'], $data['field_name'])) {
    FieldConfig::create($data)
      ->save();
  }
  $configs = [
    'core.entity_form_display.group.opigno_course.default',
    'core.entity_view_display.group.opigno_course.default',
  ];
  $config_storage = \Drupal::service('config.storage');
  foreach ($configs as $item) {
    $data = $storage
      ->read($item);
    $config_storage
      ->write($item, $data);
  }
}