protected PathValidator::getUrl($path, $access_check)
Helper for getUrlIfValid() and getUrlIfValidWithoutAccessCheck().
File
- core/lib/Drupal/Core/Path/PathValidator.php, line 94
Class
- PathValidator
- Provides a default path validator and access checker.
Namespace
Drupal\Core\Path
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | protected function getUrl( $path , $access_check ) { $path = ltrim( $path , '/' ); $parsed_url = UrlHelper::parse( $path ); $options = []; if (! empty ( $parsed_url [ 'query' ])) { $options [ 'query' ] = $parsed_url [ 'query' ]; } if (! empty ( $parsed_url [ 'fragment' ])) { $options [ 'fragment' ] = $parsed_url [ 'fragment' ]; } if ( $parsed_url [ 'path' ] == '<front>' ) { return new Url( '<front>' , [], $options ); } elseif ( $parsed_url [ 'path' ] == '<none>' ) { return new Url( '<none>' , [], $options ); } elseif (UrlHelper::isExternal( $path ) && UrlHelper::isValid( $path )) { if ( empty ( $parsed_url [ 'path' ])) { return FALSE; } return Url::fromUri( $path ); } $request = Request::create( '/' . $path ); $attributes = $this ->getPathAttributes( $path , $request , $access_check ); if (! $attributes ) { return FALSE; } $route_name = $attributes [RouteObjectInterface::ROUTE_NAME]; $route_parameters = $attributes [ '_raw_variables' ]->all(); return new Url( $route_name , $route_parameters , $options + [ 'query' => $request ->query->all()]); } |
Please login to continue.