You are here

public static function WebformArrayHelper::addPrefix in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Utility/WebformArrayHelper.php \Drupal\webform\Utility\WebformArrayHelper::addPrefix()

Add prefix to all top level keys in an associative array.

Parameters

array $array: An associative array.

string $prefix: Prefix to be prepended to all keys.

Return value

array An associative array with all top level keys prefixed.

9 calls to WebformArrayHelper::addPrefix()
OptionsBase::form in src/Plugin/WebformElement/OptionsBase.php
Gets the actual configuration webform array to be built.
WebformArrayHelperTest::testPrefixing in tests/src/Unit/Utility/WebformArrayHelperTest.php
Tests prefix an associative array.
WebformElementBase::buildConfigurationForm in src/Plugin/WebformElementBase.php
Form constructor.
WebformElementBase::getConfigurationFormProperties in src/Plugin/WebformElementBase.php
Get an associative array of element properties from configuration webform.
WebformElementComposite::validateWebformElementComposite in src/Element/WebformElementComposite.php
Validates a webform element composite (builder) element.

... See full list

File

src/Utility/WebformArrayHelper.php, line 183

Class

WebformArrayHelper
Provides helper to operate on arrays.

Namespace

Drupal\webform\Utility

Code

public static function addPrefix(array $array, $prefix = '#') {
  $prefixed_array = [];
  foreach ($array as $key => $value) {
    if ($key[0] !== $prefix) {
      $key = $prefix . $key;
    }
    $prefixed_array[$key] = $value;
  }
  return $prefixed_array;
}