You are here

public static function Tags::encode in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::encode()
  2. 9 core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::encode()

Encodes a tag string, taking care of special cases like commas and quotes.

Parameters

string $tag: A tag string.

Return value

string The encoded string.

3 calls to Tags::encode()
EntityAutocomplete::getEntityLabels in core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
Converts an array of entity objects into a string of entity labels.
EntityAutocompleteMatcher::getMatches in core/lib/Drupal/Core/Entity/EntityAutocompleteMatcher.php
EntityAutocompleteTest::testEntityReferenceAutocompletion in core/tests/Drupal/KernelTests/Core/Entity/EntityAutocompleteTest.php
Tests autocompletion edge cases with slashes in the names.

File

core/lib/Drupal/Component/Utility/Tags.php, line 51

Class

Tags
Defines a class that can explode and implode tags.

Namespace

Drupal\Component\Utility

Code

public static function encode($tag) {
  if (strpos($tag, ',') !== FALSE || strpos($tag, '"') !== FALSE) {
    return '"' . str_replace('"', '""', $tag) . '"';
  }
  return $tag;
}