You are here

function webform_update_8021 in Webform 6.x

Same name and namespace in other branches
  1. 8.5 includes/webform.install.update.inc \webform_update_8021()

Issue #2858139: Add OptGroup support to WebformOption entity.

File

includes/webform.install.update.inc, line 416
Archived Webform update hooks.

Code

function webform_update_8021() {
  _webform_update_options_settings();

  // Get WebformOptions category from config/install.
  $webform_options = WebformOptions::loadMultiple();
  $config_install_path = drupal_get_path('module', 'webform') . '/config/install';
  foreach ($webform_options as $id => $webform_option) {
    if (!$webform_option
      ->get('category')) {
      if (file_exists("{$config_install_path}/webform.webform_options.{$id}.yml")) {
        $yaml = file_get_contents("{$config_install_path}/webform.webform_options.{$id}.yml");
        $data = Yaml::decode($yaml);
        $webform_option
          ->set('category', $data['category']);
        $webform_option
          ->save();
      }
    }
  }
}