public static function AssociativeArray::processAssociativeArray in Map Widget 8
Form API callback: Processes an associative array form element.
This method is assigned as a #process callback in getInfo() method.
File
- src/
Element/ AssociativeArray.php, line 99
Class
- AssociativeArray
- Class KeyValuePair provides a form element for entering paired values.
Namespace
Drupal\map_widget\ElementCode
public static function processAssociativeArray(&$element, FormStateInterface $form_state, &$complete_form) {
$elementIndex = 0;
if (empty($element['#default_value'])) {
// One empty pair if there is no value.
$element[$elementIndex] = self::arrayElementForm('', '', $element['#size'], $element['#key_placeholder'], $element['#value_placeholder'], $element['#required']);
}
foreach ($element['#default_value'] as $key => $value) {
// Each key/value pair in it's own mini form.
$element[$elementIndex] = self::arrayElementForm($key, $value, $element['#size'], $element['#key_placeholder'], $element['#value_placeholder'], $element['#required']);
$elementIndex++;
}
for ($extra = $elementIndex; $extra < $element['#count']; $extra++) {
// Add extra empty pairs if the count is more than then number of pairs.
$element[$extra] = self::arrayElementForm('', '', $element['#size'], $element['#key_placeholder'], $element['#value_placeholder'], FALSE);
}
return $element;
}