2006-01-24 08:18:26 +00:00
|
|
|
<?php
|
2006-01-23 07:54:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
2012-11-21 15:29:04 +00:00
|
|
|
* Functions to handle paths in Drupal.
|
2006-01-23 07:54:08 +00:00
|
|
|
*/
|
|
|
|
|
2014-03-01 04:58:58 +00:00
|
|
|
use Drupal\Core\ParamConverter\ParamNotConvertedException;
|
2014-03-21 12:35:45 +00:00
|
|
|
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
2013-03-09 05:46:28 +00:00
|
|
|
|
2006-04-24 19:25:37 +00:00
|
|
|
/**
|
|
|
|
* Check if the current page is the front page.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Boolean value: TRUE if the current page is the front page; FALSE if otherwise.
|
2014-07-13 08:53:01 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* \Drupal\Core\Path\PathMatcherInterface::isFrontPage() instead.
|
2006-04-24 19:25:37 +00:00
|
|
|
*/
|
|
|
|
function drupal_is_front_page() {
|
2014-07-13 08:53:01 +00:00
|
|
|
return \Drupal::service('path.matcher')->isFrontPage();
|
2006-04-24 19:25:37 +00:00
|
|
|
}
|
2007-10-16 14:10:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a path matches any pattern in a set of patterns.
|
|
|
|
*
|
|
|
|
* @param $path
|
|
|
|
* The path to match.
|
|
|
|
* @param $patterns
|
|
|
|
* String containing a set of patterns separated by \n, \r or \r\n.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* Boolean value: TRUE if the path matches a pattern, FALSE otherwise.
|
2014-06-08 22:13:36 +00:00
|
|
|
*
|
|
|
|
* @deprecated as of Drupal 8.0. Use
|
|
|
|
* \Drupal\Core\Path\PathMatcherInterface::matchPath() instead.
|
2007-10-16 14:10:33 +00:00
|
|
|
*/
|
|
|
|
function drupal_match_path($path, $patterns) {
|
2014-06-08 22:13:36 +00:00
|
|
|
return \Drupal::service('path.matcher')->matchPath($path, $patterns);
|
2007-10-16 14:10:33 +00:00
|
|
|
}
|
2009-05-06 15:51:36 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current URL path of the page being viewed.
|
|
|
|
*
|
|
|
|
* Examples:
|
|
|
|
* - http://example.com/node/306 returns "node/306".
|
|
|
|
* - http://example.com/drupalfolder/node/306 returns "node/306" while
|
|
|
|
* base_path() returns "/drupalfolder/".
|
|
|
|
* - http://example.com/path/alias (which is a path alias for node/306) returns
|
|
|
|
* "node/306" as opposed to the path alias.
|
|
|
|
*
|
2014-06-26 10:47:01 +00:00
|
|
|
* @return string
|
2009-05-06 15:51:36 +00:00
|
|
|
* The current Drupal URL path.
|
2010-01-29 22:40:41 +00:00
|
|
|
*
|
|
|
|
* @see request_path()
|
2009-05-06 15:51:36 +00:00
|
|
|
*/
|
|
|
|
function current_path() {
|
2012-08-06 19:09:08 +00:00
|
|
|
// @todo Remove the check for whether the request service exists and the
|
|
|
|
// fallback code below, once the path alias logic has been figured out in
|
|
|
|
// http://drupal.org/node/1269742.
|
2014-07-14 14:58:53 +00:00
|
|
|
if ($request = \Drupal::request()) {
|
|
|
|
$path = $request->attributes->get('_system_path');
|
2013-02-06 12:47:22 +00:00
|
|
|
if ($path !== NULL) {
|
|
|
|
return $path;
|
|
|
|
}
|
2012-07-22 23:40:08 +00:00
|
|
|
}
|
2012-08-06 19:09:08 +00:00
|
|
|
// If we are outside the request scope, fall back to using the path stored in
|
|
|
|
// _current_path().
|
2012-04-29 15:16:27 +00:00
|
|
|
return _current_path();
|
2009-05-06 15:51:36 +00:00
|
|
|
}
|
2009-06-01 11:23:27 +00:00
|
|
|
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
/**
|
2013-01-10 23:50:55 +00:00
|
|
|
* Determines whether a path is in the administrative section of the site.
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
*
|
2013-01-10 23:50:55 +00:00
|
|
|
* By default, paths are considered to be non-administrative. If a path does
|
|
|
|
* not match any of the patterns in path_get_admin_paths(), or if it matches
|
|
|
|
* both administrative and non-administrative patterns, it is considered
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
* non-administrative.
|
|
|
|
*
|
|
|
|
* @param $path
|
|
|
|
* A Drupal path.
|
2010-07-16 02:51:44 +00:00
|
|
|
*
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
* @return
|
|
|
|
* TRUE if the path is administrative, FALSE otherwise.
|
|
|
|
*
|
2014-03-21 12:35:45 +00:00
|
|
|
* @deprecated Use \Drupal::service('router.admin_context')->isAdminRoute()
|
|
|
|
* service instead.
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
*/
|
|
|
|
function path_is_admin($path) {
|
2014-03-21 12:35:45 +00:00
|
|
|
try {
|
|
|
|
$parameters = \Drupal::service('router')->match('/' . $path);
|
|
|
|
$route = $parameters[RouteObjectInterface::ROUTE_OBJECT];
|
|
|
|
return \Drupal::service('router.admin_context')->isAdminRoute($route);
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
}
|
2014-03-21 12:35:45 +00:00
|
|
|
catch (ParamNotConvertedException $e) {
|
|
|
|
return FALSE;
|
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-17 13:10:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks a path exists and the current user has access to it.
|
|
|
|
*
|
2014-03-01 04:58:58 +00:00
|
|
|
* @param string $path
|
2009-12-17 13:10:19 +00:00
|
|
|
* The path to check.
|
|
|
|
*
|
2014-03-01 04:58:58 +00:00
|
|
|
* @return bool
|
2009-12-17 13:10:19 +00:00
|
|
|
* TRUE if it is a valid path AND the current user has access permission,
|
|
|
|
* FALSE otherwise.
|
2014-07-15 09:11:36 +00:00
|
|
|
*
|
|
|
|
* @deprecated Use \Drupal::service('path.validator')->isValid($path) service
|
|
|
|
* instead.
|
2009-12-17 13:10:19 +00:00
|
|
|
*/
|
2014-03-01 04:58:58 +00:00
|
|
|
function drupal_valid_path($path) {
|
2014-07-15 09:11:36 +00:00
|
|
|
return \Drupal::service('path.validator')->isValid($path);
|
2009-12-17 13:10:19 +00:00
|
|
|
}
|