Generates a unique ID for an item.

These items are typically fields, filters, sort criteria, or arguments.

Parameters

int $requested_id: The requested ID for the item.

array $existing_items: An array of existing items, keyed by their IDs.

Return value

string A unique ID. This will be equal to $requested_id if no item 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.

1 call to views_db_object::generate_item_id()
views_db_object::add_item in includes/view.inc
Add an item with a handler to the view.

File

includes/view.inc, line 2475
views_objects Objects that represent a View or part of a view

Class

views_db_object

Code

public static function generate_item_id($requested_id, $existing_items) {
  $count = 0;
  $id = $requested_id;
  while (!empty($existing_items[$id])) {
    $id = $requested_id . '_' . ++$count;
  }
  return $id;
}