You are here

public static function ViewExecutable::generateHandlerId in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/ViewExecutable.php \Drupal\views\ViewExecutable::generateHandlerId()

Generates a unique ID for an handler instance.

These handler instances are typically fields, filters, sort criteria, or arguments.

Parameters

string $requested_id: The requested ID for the handler instance.

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

Return value

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.

3 calls to ViewExecutable::generateHandlerId()
taxonomy_post_update_handle_publishing_status_addition_in_views in core/modules/taxonomy/taxonomy.post_update.php
Add a 'published' = TRUE filter for all Taxonomy term views and converts existing ones that were using the 'content_translation_status' field.
ViewExecutable::addHandler in core/modules/views/src/ViewExecutable.php
Adds an instance of a handler to the view.
ViewExecutableTest::testGenerateHandlerId in core/modules/views/tests/src/Unit/ViewExecutableTest.php
@covers ::generateHandlerId

File

core/modules/views/src/ViewExecutable.php, line 2229

Class

ViewExecutable
Represents a view as a whole.

Namespace

Drupal\views

Code

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