function Tags::encode

Same name in other branches
  1. 9 core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::encode()
  2. 10 core/lib/Drupal/Component/Utility/Tags.php \Drupal\Component\Utility\Tags::encode()
  3. 11.x 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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.