You are here

protected function AdminForm::sortPaging in Webform CiviCRM Integration 8.5

Fix paging on the webform.

1 call to AdminForm::sortPaging()
AdminForm::postProcess in src/AdminForm.php
Submission handler, saves CiviCRM options for a Webform node

File

src/AdminForm.php, line 2047
Webform CiviCRM module's admin form.

Class

AdminForm
@file Webform CiviCRM module's admin form.

Namespace

Drupal\webform_civicrm

Code

protected function sortPaging() {
  $elements = $this->webform
    ->getElementsInitialized();
  if (!isset($elements['contact_pagebreak'])) {
    return;
  }

  //Move contact page to top.
  if (key($elements) != 'contact_pagebreak') {
    $elements = array_merge([
      'contact_pagebreak' => $elements['contact_pagebreak'],
    ], $elements);
  }
  foreach ($elements as $key => &$element) {
    if (strpos($key, 'civicrm') !== 0 || isset($element['#parent']) || !empty($element['#webform_parent_key']) || empty($element['#type']) || $element['#type'] == 'webform_wizard_page') {
      continue;
    }
    $page = strpos($key, '_contribution_') !== FALSE ? 'contribution_pagebreak' : 'contact_pagebreak';
    $elements[$page][$key] = $element;
    unset($elements[$key]);
  }
  $this->webform
    ->setElements($elements);
  $this->webform
    ->save();
}