'', 'placeholder_title' => '', ] + parent::defaultSettings(); } /** * Gets the URI without the 'internal:' or 'entity:' scheme. * * The following two forms of URIs are transformed: * - 'entity:' URIs: to entity autocomplete ("label (entity id)") strings; * - 'internal:' URIs: the scheme is stripped. * * This method is the inverse of ::getUserEnteredStringAsUri(). * * @param string $uri * The URI to get the displayable string for. * * @return string * * @see static::getUserEnteredStringAsUri() */ protected static function getUriAsDisplayableString($uri) { $scheme = parse_url($uri, PHP_URL_SCHEME); // By default, the displayable string is the URI. $displayable_string = $uri; // A different displayable string may be chosen in case of the 'internal:' // or 'entity:' built-in schemes. if ($scheme === 'internal') { $uri_reference = explode(':', $uri, 2)[1]; // @todo '' is valid input for BC reasons, may be removed by // https://www.drupal.org/node/2421941 $path = parse_url($uri, PHP_URL_PATH); if ($path === '/') { $uri_reference = '' . substr($uri_reference, 1); } $displayable_string = $uri_reference; } elseif ($scheme === 'entity') { [$entity_type, $entity_id] = explode('/', substr($uri, 7), 2); // Show the 'entity:' URI as the entity autocomplete would. // @todo Support entity types other than 'node'. Will be fixed in // https://www.drupal.org/node/2423093. if ($entity_type == 'node' && $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($entity_id)) { $displayable_string = EntityAutocomplete::getEntityLabels([$entity]); } } elseif ($scheme === 'route') { $displayable_string = ltrim($displayable_string, 'route:'); } return $displayable_string; } /** * Gets the user-entered string as a URI. * * The following two forms of input are mapped to URIs: * - entity autocomplete ("label (entity id)") strings: to 'entity:' URIs; * - strings without a detectable scheme: to 'internal:' URIs. * * This method is the inverse of ::getUriAsDisplayableString(). * * @param string $string * The user-entered string. * * @return string * The URI, if a non-empty $uri was passed. * * @see static::getUriAsDisplayableString() */ protected static function getUserEnteredStringAsUri($string) { // By default, assume the entered string is a URI. $uri = trim($string); // Detect entity autocomplete string, map to 'entity:' URI. $entity_id = EntityAutocomplete::extractEntityIdFromAutocompleteInput($string); if ($entity_id !== NULL) { // @todo Support entity types other than 'node'. Will be fixed in // https://www.drupal.org/node/2423093. $uri = 'entity:node/' . $entity_id; } // Support linking to nothing. elseif (in_array($string, ['', '', '