You are here

function webform_update_8011 in Webform 6.x

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

Issue #2845028: Refactor and rework element formatting to better support multiple values.

File

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

Code

function webform_update_8011() {

  // Update admin.settings format to support
  // 'formats.{element_type}.item' and 'formats.{element_type}.items'.
  $admin_config = \Drupal::configFactory()
    ->getEditable('webform.settings');
  $data = $admin_config
    ->getRawData();
  if (!empty($data['format'])) {
    foreach ($data['format'] as $element_type => $element_format) {
      if (is_string($element_format)) {
        $data['format'][$element_type] = [
          'item' => $element_format,
        ];
      }
    }
    $admin_config
      ->setData($data)
      ->save();
  }

  // Update webform element to support #format_items.
  $config_factory = \Drupal::configFactory();

  // Update 'webform.webform.*' configuration.
  foreach ($config_factory
    ->listAll('webform.webform.') as $webform_config_name) {
    $webform_config = $config_factory
      ->getEditable($webform_config_name);

    // Get data.
    $data = $webform_config
      ->getRawData();
    if (strpos($data['elements'], "'#format'") === FALSE) {
      continue;
    }
    $elements = Yaml::decode($data['elements']);
    _webform_update_8011($elements);
    $data['elements'] = Yaml::encode($elements);
    $webform_config
      ->setData($data);
    $webform_config
      ->save();
  }
}