public static EntityAutocomplete::extractEntityIdFromAutocompleteInput($input)
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.
File
- core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php, line 348
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 parenthesis when it's a
// number.
if (preg_match("/.+\s\((\d+)\)/", $input, $matches)) {
$match = $matches[1];
}
// Match the ID when it's a string (e.g. for config entity types).
elseif (preg_match("/.+\s\(([\w.]+)\)/", $input, $matches)) {
$match = $matches[1];
}
return $match;
}
Please login to continue.