Generates a unique ID for an handler instance.
These handler instances are typically fields, filters, sort criteria, or arguments.
string $requested_id: The requested ID for the handler instance.
array $existing_items: An array of existing handler instancess, keyed by their IDs.
string A unique ID. This will be equal to $requested_id if no handler instance with that ID already exists. Otherwise, it will be appended with an integer to make it unique, e.g., "{$requested_id}_1", "{$requested_id}_2", etc.
public static function generateItemId($requested_id, $existing_items) {
$count = 0;
$id = $requested_id;
while (!empty($existing_items[$id])) {
$id = $requested_id . '_' . ++$count;
}
return $id;
}