예제 #1
0
 /**
  * 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 an URI.
     $uri = $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;
     } elseif (!empty($string) && parse_url($string, PHP_URL_SCHEME) === NULL) {
         // @todo '<front>' is valid input for BC reasons, may be removed by
         //   https://www.drupal.org/node/2421941
         // - '<front>' -> '/'
         // - '<front>#foo' -> '/#foo'
         if (strpos($string, '<front>') === 0) {
             $string = '/' . substr($string, strlen('<front>'));
         }
         $uri = 'internal:' . $string;
     }
     return $uri;
 }