You are here

function _webform_update_webform_setting in Webform 6.x

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

Update webform setting to reflect changes in the default settings.

Parameters

array $data: A webform's raw configuration data from webform.webform.*.yml.

Return value

array Updated raw configuration data.

2 calls to _webform_update_webform_setting()
WebformDevelCommands::drush_webform_devel_config_update in modules/webform_devel/src/Commands/WebformDevelCommands.php
Executes devel export config.
_webform_update_webform_settings in includes/webform.install.inc
Update webform settings to reflect changes in the default settings.

File

includes/webform.install.inc, line 101
Webform install helper functions.

Code

function _webform_update_webform_setting(array $data) {
  $default_properties = [
    'uuid' => NULL,
    'langcode' => 'en',
    'status' => WebformInterface::STATUS_OPEN,
    'dependencies' => [],
    'third_party_settings' => [],
    'open' => NULL,
    'close' => NULL,
    'weight' => 0,
    'uid' => '',
    'template' => FALSE,
    'archive' => FALSE,
    'id' => '',
    'title' => '',
    'description' => '',
    'category' => '',
    'elements' => '',
    'css' => '',
    'javascript' => '',
    'settings' => [],
    'access' => [],
    'handlers' => [],
    'variants' => [],
  ];
  $default_settings = Webform::getDefaultSettings();

  // Always apply the default properties.
  $properties = $default_properties;

  // Now apply defined properties.
  foreach ($data as $name => $value) {
    $properties[$name] = $value;
  }

  // Empty settings.
  if (empty($properties['third_party_settings'])) {
    unset($properties['third_party_settings']);
  }

  // Set properties.
  $data = $properties;

  // Always apply the default settings.
  $settings = $default_settings;

  // Now apply custom settings.
  foreach ($data['settings'] as $name => $value) {
    $settings[$name] = $value;
  }

  // Set settings.
  $data['settings'] = _webform_update_webform_setting_settings($settings);

  // Set access.

  /** @var \Drupal\webform\WebformAccessRulesManagerInterface $access_rules_manager */
  $access_rules_manager = \Drupal::service('webform.access_rules_manager');
  $data['access'] += $access_rules_manager
    ->getDefaultAccessRules();
  return $data;
}