You are here

protected function WebformSubmissionForm::addStatesPrefix in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformSubmissionForm.php \Drupal\webform\WebformSubmissionForm::addStatesPrefix()

Add unique class prefix to all :input #states selectors.

Parameters

array $array: An associative array.

Return value

array An associative array with unique class prefix added to all :input #states selectors.

1 call to WebformSubmissionForm::addStatesPrefix()
WebformSubmissionForm::prepareElements in src/WebformSubmissionForm.php
Prepare webform elements.

File

src/WebformSubmissionForm.php, line 2528

Class

WebformSubmissionForm
Provides a webform to collect and edit submissions.

Namespace

Drupal\webform

Code

protected function addStatesPrefix(array $array) {
  $prefixed_array = [];
  foreach ($array as $key => $value) {
    if (strpos($key, ':input') === 0) {
      $key = $this->statesPrefix . ' ' . $key;
      $prefixed_array[$key] = $value;
    }
    elseif (is_array($value)) {
      $prefixed_array[$key] = $this
        ->addStatesPrefix($value);
    }
    else {
      $prefixed_array[$key] = $value;
    }
  }
  return $prefixed_array;
}