protected static function FormHelper::processStatesArray

protected static FormHelper::processStatesArray(array &$conditions, $search, $replace)

Helper function for self::rewriteStatesSelector().

Parameters

array $conditions: States conditions array.

string $search: A partial or entire jQuery selector string to replace in #states.

string $replace: The string to replace all instances of $search with.

File

core/lib/Drupal/Core/Form/FormHelper.php, line 47

Class

FormHelper
Provides helpers to operate on forms.

Namespace

Drupal\Core\Form

Code

protected static function processStatesArray(array &$conditions, $search, $replace) {
  // Retrieve the keys to make it easy to rename a key without changing the
  // order of an array.
  $keys = array_keys($conditions);
  $update_keys = FALSE;
  foreach ($conditions as $id => $values) {
    if (strpos($id, $search) !== FALSE) {
      $update_keys = TRUE;
      $new_id = str_replace($search, $replace, $id);
      // Replace the key and keep the array in the same order.
      $index = array_search($id, $keys, TRUE);
      $keys[$index] = $new_id;
    }
    elseif (is_array($values)) {
      static::processStatesArray($conditions[$id], $search, $replace);
    }
  }
  // Updates the states conditions keys if necessary.
  if ($update_keys) {
    $conditions = array_combine($keys, array_values($conditions));
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormHelper.php/function/FormHelper::processStatesArray/8.1.x