You are here

function _webform_update_8046_convert_data in Webform 6.x

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

Convert webform config data from settings.buttons to use the 'webform_actions' element.

Parameters

array $data: Webform config data.

Return value

array Webform config data with 'webform_actions' element.

1 call to _webform_update_8046_convert_data()
webform_update_8046 in includes/webform.install.update.inc
Issue #2878193: Allow actions (aka submit buttons) to be placed anywhere on a webform.

File

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

Code

function _webform_update_8046_convert_data(array $data) {
  $button_names = [
    'submit',
    'draft',
    'wizard_prev',
    'wizard_next',
    'preview_prev',
    'preview_next',
  ];

  // Build actions element from webform's settings.
  $actions_element = [];
  $settings = $data['settings'];
  foreach ($button_names as $button_name) {
    $settings_prefix = $button_name === 'submit' ? 'form_' . $button_name : $button_name . '_button';
    if (!empty($settings[$settings_prefix . '_label'])) {
      $actions_element['#' . $button_name . '__label'] = $settings[$settings_prefix . '_label'];
    }
    if (!empty($settings[$settings_prefix . '_attributes'])) {
      $actions_element['#' . $button_name . '__attributes'] = $settings[$settings_prefix . '_attributes'];
    }
    unset($settings[$settings_prefix . '_label']);
    unset($settings[$settings_prefix . '_attributes']);
  }
  $data['settings'] = $settings;

  // Append actions element to elements.
  if ($actions_element) {
    $elements = Yaml::decode($data['elements']);
    $elements['actions'] = [
      '#type' => 'webform_actions',
      '#title' => (string) t('Submit button(s)'),
    ] + $actions_element;
    $data['elements'] = Yaml::encode($elements);
  }
  return $data;
}