You are here

public static function Tags::encode in Drupal 8

Same name and namespace in other branches
  1. 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.

5 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
Gets matched labels based on a given search string.
EntityAutocompleteTest::testEntityReferenceAutocompletion in core/tests/Drupal/KernelTests/Core/Entity/EntityAutocompleteTest.php
Tests autocompletion edge cases with slashes in the names.
Tags::implode in core/lib/Drupal/Component/Utility/Tags.php
Implodes an array of tags into a string.
taxonomy_implode_tags in core/modules/taxonomy/taxonomy.module
Implodes a list of tags of a certain vocabulary into a string.

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;
}