function EntityAutocomplete::extractEntityIdFromAutocompleteInput

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php \Drupal\Core\Entity\Element\EntityAutocomplete::extractEntityIdFromAutocompleteInput()
  2. 10 core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php \Drupal\Core\Entity\Element\EntityAutocomplete::extractEntityIdFromAutocompleteInput()
  3. 11.x core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php \Drupal\Core\Entity\Element\EntityAutocomplete::extractEntityIdFromAutocompleteInput()

Extracts the entity ID from the autocompletion result.

Parameters

string $input: The input coming from the autocompletion result.

Return value

mixed|null An entity ID or NULL if the input does not contain one.

2 calls to EntityAutocomplete::extractEntityIdFromAutocompleteInput()
EntityAutocomplete::validateEntityAutocomplete in core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
Form element validation handler for entity_autocomplete elements.
LinkWidget::getUserEnteredStringAsUri in core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
Gets the user-entered string as a URI.

File

core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php, line 400

Class

EntityAutocomplete
Provides an entity autocomplete form element.

Namespace

Drupal\Core\Entity\Element

Code

public static function extractEntityIdFromAutocompleteInput($input) {
    $match = NULL;
    // Take "label (entity id)', match the ID from inside the parentheses.
    // @todo Add support for entities containing parentheses in their ID.
    // @see https://www.drupal.org/node/2520416
    if (preg_match("/.+\\s\\(([^\\)]+)\\)/", $input, $matches)) {
        $match = $matches[1];
    }
    return $match;
}

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