diff --git a/core/includes/common.inc b/core/includes/common.inc index 23069cb..6405c0b 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -2176,7 +2176,7 @@ function url($path = NULL, array $options = array()) { } elseif (!empty($path) && !$options['alias']) { $langcode = isset($options['language']) && isset($options['language']->langcode) ? $options['language']->langcode : ''; - $alias = drupal_get_path_alias($original_path, $langcode); + $alias = path()->getPathAlias($original_path, $langcode); if ($alias != $original_path) { $path = $alias; } @@ -2498,7 +2498,7 @@ function drupal_deliver_html_page($page_callback_result) { $_GET['destination'] = current_path(); } - $path = drupal_get_normal_path(variable_get('site_404', '')); + $path = path()->getNormalPath(variable_get('site_404', '')); if ($path && $path != current_path()) { // Custom 404 handler. Set the active item in case there are tabs to // display, or other dependencies on the path. @@ -2527,7 +2527,7 @@ function drupal_deliver_html_page($page_callback_result) { $_GET['destination'] = current_path(); } - $path = drupal_get_normal_path(variable_get('site_403', '')); + $path = path()->getNormalPath(variable_get('site_403', '')); if ($path && $path != current_path()) { // Custom 403 handler. Set the active item in case there are tabs to // display or other dependencies on the path. diff --git a/core/includes/menu.inc b/core/includes/menu.inc index 581a6ce..08fdedd 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -2992,7 +2992,7 @@ function _menu_delete_item($item, $force = FALSE) { * @param $item * An associative array representing a menu link item, with elements: * - link_path: (required) The path of the menu item, which should be - * normalized first by calling drupal_get_normal_path() on it. + * normalized first by calling path()->getNormalPath() on it. * - link_title: (required) Title to appear in menu for the link. * - menu_name: (optional) The machine name of the menu for the link. * Defaults to 'navigation'. diff --git a/core/includes/path.inc b/core/includes/path.inc index 0c7e4d4..802fc2a 100644 --- a/core/includes/path.inc +++ b/core/includes/path.inc @@ -1,5 +1,7 @@ getNormalPath(). $path = _current_path(); // If on the front page, resolve to the front page path, including for calls - // to current_path() while drupal_get_normal_path() is in progress. + // to current_path() while path()->getNormalPath() is in progress. if (empty($path)) { $path = variable_get('site_frontpage', 'user'); _current_path($path); } // Normalize the path. - _current_path(drupal_get_normal_path($path)); + $path = path()->getNormalPath($path); + _current_path($path); } /** @@ -133,7 +149,7 @@ function drupal_lookup_path($action, $path = '', $langcode = NULL) { if (isset($cache['map'][$langcode][$path])) { return $cache['map'][$langcode][$path]; } - // Check the path whitelist, if the top_level part before the first / + // Check the path whitelist, if the top-level part before the first / // is not in the list, then there is no need to do anything further, // it is not in the database. elseif (!isset($cache['whitelist'][strtok($path, '/')])) { @@ -226,64 +242,6 @@ function drupal_cache_system_paths() { } /** - * Given an internal Drupal path, return the alias set by the administrator. - * - * If no path is provided, the function will return the alias of the current - * page. - * - * @param $path - * An internal Drupal path. - * @param $langcode - * An optional language code to look up the path in. - * - * @return - * An aliased path if one was found, or the original path if no alias was - * found. - */ -function drupal_get_path_alias($path = NULL, $langcode = NULL) { - // If no path is specified, use the current page's path. - if ($path == NULL) { - $path = current_path(); - } - $result = $path; - if ($alias = drupal_lookup_path('alias', $path, $langcode)) { - $result = $alias; - } - return $result; -} - -/** - * Given a path alias, return the internal path it represents. - * - * @param $path - * A Drupal path alias. - * @param $langcode - * An optional language code to look up the path in. - * - * @return - * The internal path represented by the alias, or the original alias if no - * internal path was found. - */ -function drupal_get_normal_path($path, $langcode = NULL) { - $original_path = $path; - - // Lookup the path alias first. - if ($source = drupal_lookup_path('source', $path, $langcode)) { - $path = $source; - } - - // Allow other modules to alter the inbound URL. We cannot use drupal_alter() - // here because we need to run hook_url_inbound_alter() in the reverse order - // of hook_url_outbound_alter(). - foreach (array_reverse(module_implements('url_inbound_alter')) as $module) { - $function = $module . '_url_inbound_alter'; - $function($path, $original_path, $langcode); - } - - return $path; -} - -/** * Check if the current page is the front page. * * @return @@ -392,11 +350,10 @@ function drupal_path_alias_whitelist_rebuild($source = NULL) { } /** - * Fetch a specific URL alias from the database. + * Menu wildcard path loader. * - * @param $conditions - * A string representing the source, a number representing the pid, or an - * array of query conditions. + * @param $pid + * A number representing the pid. * * @return * FALSE if no alias was found or an associative array containing the @@ -406,78 +363,8 @@ function drupal_path_alias_whitelist_rebuild($source = NULL) { * - pid: Unique path alias identifier. * - langcode: The language code of the alias. */ -function path_load($conditions) { - if (is_numeric($conditions)) { - $conditions = array('pid' => $conditions); - } - elseif (is_string($conditions)) { - $conditions = array('source' => $conditions); - } - elseif (!is_array($conditions)) { - return FALSE; - } - $select = db_select('url_alias'); - foreach ($conditions as $field => $value) { - $select->condition($field, $value); - } - return $select - ->fields('url_alias') - ->execute() - ->fetchAssoc(); -} - -/** - * Save a path alias to the database. - * - * @param $path - * An associative array containing the following keys: - * - source: The internal system path. - * - alias: The URL alias. - * - pid: (optional) Unique path alias identifier. - * - langcode: (optional) The language code of the alias. - */ -function path_save(&$path) { - $path += array('langcode' => LANGUAGE_NOT_SPECIFIED); - - // Load the stored alias, if any. - if (!empty($path['pid']) && !isset($path['original'])) { - $path['original'] = path_load($path['pid']); - } - - if (empty($path['pid'])) { - drupal_write_record('url_alias', $path); - module_invoke_all('path_insert', $path); - } - else { - drupal_write_record('url_alias', $path, array('pid')); - module_invoke_all('path_update', $path); - } - - // Clear internal properties. - unset($path['original']); - - // Clear the static alias cache. - drupal_clear_path_cache($path['source']); -} - -/** - * Delete a URL alias. - * - * @param $criteria - * A number representing the pid or an array of criteria. - */ -function path_delete($criteria) { - if (!is_array($criteria)) { - $criteria = array('pid' => $criteria); - } - $path = path_load($criteria); - $query = db_delete('url_alias'); - foreach ($criteria as $field => $value) { - $query->condition($field, $value); - } - $query->execute(); - module_invoke_all('path_delete', $path); - drupal_clear_path_cache($path['source']); +function path_load($pid) { + return path()->load($pid); } /** @@ -580,14 +467,3 @@ function drupal_valid_path($path, $dynamic_allowed = FALSE) { return $item && $item['access']; } -/** - * Clear the path cache. - * - * @param $source - * An optional system path for which an alias is being changed. - */ -function drupal_clear_path_cache($source = NULL) { - // Clear the drupal_lookup_path() static cache. - drupal_static_reset('drupal_lookup_path'); - drupal_path_alias_whitelist_rebuild($source); -} diff --git a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php index 9104544..2834868 100644 --- a/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/PathSubscriber.php @@ -30,7 +30,7 @@ class PathSubscriber extends PathListenerBase implements EventSubscriberInterfac $path = $this->extractPath($request); - $path = drupal_get_normal_path($path); + $path = path()->getNormalPath($path); $this->setPath($request, $path); } diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index b163395..dccfce7 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -94,7 +94,7 @@ class ExceptionController { $system_path = $request->attributes->get('system_path'); watchdog('access denied', $system_path, NULL, WATCHDOG_WARNING); - $path = drupal_get_normal_path(variable_get('site_403', '')); + $path = path()->getNormalPath(variable_get('site_403', '')); if ($path && $path != $system_path) { // Keep old path for reference, and to allow forms to redirect to it. if (!isset($_GET['destination'])) { @@ -160,7 +160,7 @@ class ExceptionController { $_GET['destination'] = $system_path; } - $path = drupal_get_normal_path(variable_get('site_404', '')); + $path = path()->getNormalPath(variable_get('site_404', '')); if ($path && $path != $system_path) { // @todo Um, how do I specify an override URL again? Totally not clear. Do // that and sub-call the kernel rather than using meah(). diff --git a/core/lib/Drupal/Core/Path/DrupalPathRegistry.php b/core/lib/Drupal/Core/Path/DrupalPathRegistry.php new file mode 100644 index 0000000..d859ed1 --- /dev/null +++ b/core/lib/Drupal/Core/Path/DrupalPathRegistry.php @@ -0,0 +1,102 @@ + NULL, 'language' => LANGUAGE_NONE); + + // Insert or update the alias. + $status = drupal_write_record('url_alias', $path, (!empty($path['pid']) ? 'pid' : array())); + + // Verify that a record was written. + if ($status) { + if ($status === SAVED_NEW) { + module_invoke_all('path_insert', $path); + } + else { + module_invoke_all('path_update', $path); + } + $this->cacheClear($path['source']); + } + } + + public function load($conditions) { + if (is_numeric($conditions)) { + $conditions = array('pid' => $conditions); + } + elseif (is_string($conditions)) { + $conditions = array('source' => $conditions); + } + elseif (!is_array($conditions)) { + return FALSE; + } + $select = db_select('url_alias'); + foreach ($conditions as $field => $value) { + $select->condition($field, $value); + } + return $select + ->fields('url_alias') + ->execute() + ->fetchAssoc(); + } + + public function delete($conditions) { + if (!is_array($conditions)) { + $conditions = array('pid' => $conditions); + } + $path = $this->load($conditions); + $query = db_delete('url_alias'); + foreach ($conditions as $field => $value) { + $query->condition($field, $value); + } + $query->execute(); + module_invoke_all('path_delete', $path); + $this->cacheClear($path['source']); + } + + public function getNormalPath($path, $path_language = NULL) { + $original_path = $path; + + // Lookup the path alias first. + if ($source = drupal_lookup_path('source', $path, $path_language)) { + $path = $source; + } + + // Allow other modules to alter the inbound URL. We cannot use drupal_alter() + // here because we need to run hook_url_inbound_alter() in the reverse order + // of hook_url_outbound_alter(). + foreach (array_reverse(module_implements('url_inbound_alter')) as $module) { + $function = $module . '_url_inbound_alter'; + $function($path, $original_path, $path_language); + } + + return $path; + } + + public function getPathAlias($path = NULL, $path_language = NULL) { + // If no path is specified, use the current page's path. + if ($path === NULL) { + $path = _current_path(); + } + $result = $path; + if ($alias = drupal_lookup_path('alias', $path, $path_language)) { + $result = $alias; + } + return $result; + } + + public function cacheClear($source = NULL) { + drupal_static_reset('drupal_lookup_path'); + drupal_path_alias_whitelist_rebuild($source); + } +} + diff --git a/core/lib/Drupal/Core/Path/DrupalPathRegistryInterface.php b/core/lib/Drupal/Core/Path/DrupalPathRegistryInterface.php new file mode 100644 index 0000000..a00195a --- /dev/null +++ b/core/lib/Drupal/Core/Path/DrupalPathRegistryInterface.php @@ -0,0 +1,86 @@ +visibility < BLOCK_VISIBILITY_PHP) { // Compare the lowercase path alias (if any) and internal path. $path = current_path(); - $path_alias = drupal_strtolower(drupal_get_path_alias($path)); + $path_alias = drupal_strtolower(path()->getPathAlias($path)); $page_match = drupal_match_path($path_alias, $pages) || (($path != $path_alias) && drupal_match_path($path, $pages)); // When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED), // the block is displayed on all pages except those listed in $block->pages. diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php index 61fd67f..242da8a 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php @@ -101,13 +101,13 @@ class LocalePathTest extends WebTestBase { 'alias' => $custom_path, 'langcode' => LANGUAGE_NOT_SPECIFIED, ); - path_save($edit); - $lookup_path = drupal_lookup_path('alias', 'node/' . $node->nid, 'en'); + path()->save($edit); + $lookup_path = path()->getPathAlias('node/' . $node->nid, 'en'); $this->assertEqual($english_path, $lookup_path, t('English language alias has priority.')); // Same check for language 'xx'. - $lookup_path = drupal_lookup_path('alias', 'node/' . $node->nid, $prefix); + $lookup_path = path()->getPathAlias('node/' . $node->nid, $prefix); $this->assertEqual($custom_language_path, $lookup_path, t('Custom language alias has priority.')); - path_delete($edit); + path()->delete($edit); // Create language nodes to check priority of aliases. $first_node = $this->drupalCreateNode(array('type' => 'page', 'promote' => 1)); @@ -119,7 +119,7 @@ class LocalePathTest extends WebTestBase { 'alias' => $custom_path, 'langcode' => 'en', ); - path_save($edit); + path()->save($edit); // Assign a custom path alias to second node with LANGUAGE_NOT_SPECIFIED. $edit = array( @@ -127,7 +127,7 @@ class LocalePathTest extends WebTestBase { 'alias' => $custom_path, 'langcode' => LANGUAGE_NOT_SPECIFIED, ); - path_save($edit); + path()->save($edit); // Test that both node titles link to our path alias. $this->drupalGet(''); diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index 496ff88..55b5c4e 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -369,7 +369,7 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) { */ function menu_edit_item_validate($form, &$form_state) { $item = &$form_state['values']; - $normal_path = drupal_get_normal_path($item['link_path']); + $normal_path = path()->getNormalPath($item['link_path']); if ($item['link_path'] != $normal_path) { drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $item['link_path'], '%normal_path' => $normal_path))); $item['link_path'] = $normal_path; diff --git a/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php b/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php index af8b0c7..82bd1c5 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathAliasTest.php @@ -84,7 +84,7 @@ class PathAliasTest extends PathTestBase { $this->assertText($node1->title, 'Changed alias works.'); $this->assertResponse(200); - drupal_static_reset('drupal_lookup_path'); + path()->cacheClear(); // Confirm that previous alias no longer works. $this->drupalGet($previous); $this->assertNoText($node1->title, 'Previous alias no longer works.'); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index b3dba0e..e16f8ba 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -70,7 +70,7 @@ class PathLanguageTest extends PathTestBase { $this->drupalPost(NULL, $edit, t('Save')); // Clear the path lookup cache. - drupal_lookup_path('wipe'); + path()->cacheClear(); // Ensure the node was created. $french_node = $this->drupalGetNodeByTitle($edit["title"]); @@ -109,7 +109,7 @@ class PathLanguageTest extends PathTestBase { // We need to ensure that the user language preference is not taken into // account while determining the path alias language, because if this // happens we have no way to check that the path alias is valid: there is no - // path alias for French matching the english alias. So drupal_lookup_path() + // path alias for French matching the english alias. So DrupalPathRegistry // needs to use the URL language to check whether the alias is valid. $this->drupalGet($english_alias); $this->assertText($english_node->title, 'Alias for English translation works.'); @@ -133,20 +133,20 @@ class PathLanguageTest extends PathTestBase { $this->drupalGet($french_alias); $this->assertResponse(404, t('Alias for French translation is unavailable when URL language negotiation is disabled.')); - // drupal_lookup_path() has an internal static cache. Check to see that + // DrupalPathRegistry has an internal static cache. Check to see that // it has the appropriate contents at this point. - drupal_lookup_path('wipe'); - $french_node_path = drupal_lookup_path('source', $french_alias, $french_node->langcode); + path()->cacheClear(); + $french_node_path = path()->getNormalPath($french_alias, $french_node->language); $this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path works.')); // Second call should return the same path. - $french_node_path = drupal_lookup_path('source', $french_alias, $french_node->langcode); + $french_node_path = path()->getNormalPath($french_alias, $french_node->language); $this->assertEqual($french_node_path, 'node/' . $french_node->nid, t('Normal path is the same.')); // Confirm that the alias works. - $french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->langcode); + $french_node_alias = path()->getPathAlias('node/' . $french_node->nid, $french_node->language); $this->assertEqual($french_node_alias, $french_alias, t('Alias works.')); // Second call should return the same alias. - $french_node_alias = drupal_lookup_path('alias', 'node/' . $french_node->nid, $french_node->langcode); + $french_node_alias = path()->getPathAlias('node/' . $french_node->nid, $french_node->language); $this->assertEqual($french_node_alias, $french_alias, t('Alias is the same.')); } } diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc index 4188eff..4d8376f 100644 --- a/core/modules/path/path.admin.inc +++ b/core/modules/path/path.admin.inc @@ -76,7 +76,7 @@ function path_admin_overview($keys = NULL) { // If the system path maps to a different URL alias, highlight this table // row to let the user know of old aliases. - if ($data->alias != drupal_get_path_alias($data->source, $data->langcode)) { + if ($data->alias != path()->getPathAlias($data->source, $data->langcode)) { $row['class'] = array('warning'); } @@ -218,7 +218,7 @@ function path_admin_form_delete_submit($form, &$form_state) { */ function path_admin_form_validate($form, &$form_state) { $source = &$form_state['values']['source']; - $source = drupal_get_normal_path($source); + $source = path()->getNormalPath($source); $alias = $form_state['values']['alias']; $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; // Language is only set if language.module is enabled, otherwise save for all @@ -250,7 +250,7 @@ function path_admin_form_submit($form, &$form_state) { // Remove unnecessary values. form_state_values_clean($form_state); - path_save($form_state['values']); + path()->save($form_state['values']); drupal_set_message(t('The alias has been saved.')); $form_state['redirect'] = 'admin/config/search/path'; @@ -282,7 +282,7 @@ function path_admin_delete_confirm($form, &$form_state, $path) { */ function path_admin_delete_confirm_submit($form, &$form_state) { if ($form_state['values']['confirm']) { - path_delete($form_state['path']['pid']); + path()->delete($form_state['path']['pid']); $form_state['redirect'] = 'admin/config/search/path'; } } diff --git a/core/modules/path/path.api.php b/core/modules/path/path.api.php index f2c5ece..09901aa 100644 --- a/core/modules/path/path.api.php +++ b/core/modules/path/path.api.php @@ -20,7 +20,7 @@ * - pid: Unique path alias identifier. * - langcode: The language code of the alias. * - * @see path_save() + * @see DrupalPathRegistry::save() */ function hook_path_insert($path) { db_insert('mytable') @@ -41,7 +41,7 @@ function hook_path_insert($path) { * - pid: Unique path alias identifier. * - langcode: The language code of the alias. * - * @see path_save() + * @see DrupalPathRegistry::save() */ function hook_path_update($path) { db_update('mytable') @@ -60,7 +60,7 @@ function hook_path_update($path) { * - pid: Unique path alias identifier. * - langcode: The language code of the alias. * - * @see path_delete() + * @see DrupalPathRegistry::delete() */ function hook_path_delete($path) { db_delete('mytable') diff --git a/core/modules/path/path.module b/core/modules/path/path.module index d01c623..ec2e298 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -105,7 +105,7 @@ function path_form_node_form_alter(&$form, $form_state) { if ($form['#node']->langcode != LANGUAGE_NOT_SPECIFIED) { $conditions['langcode'] = $form['#node']->langcode; } - $path = path_load($conditions); + $path = path()->load($conditions); if ($path === FALSE) { $path = array(); } @@ -197,7 +197,7 @@ function path_node_insert(Node $node) { // Ensure fields for programmatic executions. $path['source'] = 'node/' . $node->nid; $path['langcode'] = isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED; - path_save($path); + path()->save($path); } } } @@ -211,14 +211,14 @@ function path_node_update(Node $node) { $path['alias'] = trim($path['alias']); // Delete old alias if user erased it. if (!empty($path['pid']) && empty($path['alias'])) { - path_delete($path['pid']); + path()->delete($path['pid']); } // Only save a non-empty alias. if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $path['source'] = 'node/' . $node->nid; $path['langcode'] = isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED; - path_save($path); + path()->save($path); } } } @@ -228,7 +228,7 @@ function path_node_update(Node $node) { */ function path_node_predelete(Node $node) { // Delete all aliases associated with this node. - path_delete(array('source' => 'node/' . $node->nid)); + path()->delete(array('source' => 'node/' . $node->nid)); } /** @@ -237,7 +237,7 @@ function path_node_predelete(Node $node) { function path_form_taxonomy_form_term_alter(&$form, $form_state) { // Make sure this does not show up on the delete confirmation form. if (empty($form_state['confirm_delete'])) { - $path = (isset($form['#term']['tid']) ? path_load('taxonomy/term/' . $form['#term']['tid']) : array()); + $path = (isset($form['#term']['tid']) ? path()->load('taxonomy/term/' . $form['#term']['tid']) : array()); if ($path === FALSE) { $path = array(); } @@ -278,7 +278,7 @@ function path_taxonomy_term_insert(Term $term) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; $path['langcode'] = LANGUAGE_NOT_SPECIFIED; - path_save($path); + path()->save($path); } } } @@ -292,14 +292,14 @@ function path_taxonomy_term_update(Term $term) { $path['alias'] = trim($path['alias']); // Delete old alias if user erased it. if (!empty($path['pid']) && empty($path['alias'])) { - path_delete($path['pid']); + path()->delete($path['pid']); } // Only save a non-empty alias. if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; $path['langcode'] = LANGUAGE_NOT_SPECIFIED; - path_save($path); + path()->save($path); } } } @@ -309,5 +309,5 @@ function path_taxonomy_term_update(Term $term) { */ function path_taxonomy_term_delete(Term $term) { // Delete all aliases associated with this term. - path_delete(array('source' => 'taxonomy/term/' . $term->tid)); + path()->delete(array('source' => 'taxonomy/term/' . $term->tid)); } diff --git a/core/modules/search/search.module b/core/modules/search/search.module index f567dae..f34cc06 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -640,7 +640,7 @@ function search_index($sid, $module, $text) { if ($tagname == 'a') { // Check if link points to a node on this site if (preg_match($node_regexp, $value, $match)) { - $path = drupal_get_normal_path($match[1]); + $path = path()->getNormalPath($match[1]); if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) { $linknid = $match[1]; if ($linknid > 0) { diff --git a/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutLinksTest.php b/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutLinksTest.php index 278b1e0..7f50497 100644 --- a/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutLinksTest.php +++ b/core/modules/shortcut/lib/Drupal/shortcut/Tests/ShortcutLinksTest.php @@ -31,7 +31,7 @@ class ShortcutLinksTest extends ShortcutTestBase { 'source' => 'node/' . $this->node->nid, 'alias' => $this->randomName(8), ); - path_save($path); + path()->save($path); // Create some paths to test. $test_cases = array( @@ -52,7 +52,7 @@ class ShortcutLinksTest extends ShortcutTestBase { $this->assertResponse(200); $saved_set = shortcut_set_load($set->set_name); $paths = $this->getShortcutInformation($saved_set, 'link_path'); - $this->assertTrue(in_array(drupal_get_normal_path($test['path']), $paths), 'Shortcut created: '. $test['path']); + $this->assertTrue(in_array(path()->getNormalPath($test['path']), $paths), 'Shortcut created: '. $test['path']); $this->assertLink($title, 0, 'Shortcut link found on the page.'); } } diff --git a/core/modules/shortcut/shortcut.admin.inc b/core/modules/shortcut/shortcut.admin.inc index 9f1888a..1d8cd12 100644 --- a/core/modules/shortcut/shortcut.admin.inc +++ b/core/modules/shortcut/shortcut.admin.inc @@ -473,7 +473,7 @@ function _shortcut_link_form_elements($shortcut_link = NULL) { ); } else { - $shortcut_link['link_path'] = drupal_get_path_alias($shortcut_link['link_path']); + $shortcut_link['link_path'] = path()->getPathAlias($shortcut_link['link_path']); } $form['shortcut_link']['#tree'] = TRUE; @@ -520,7 +520,7 @@ function shortcut_link_edit_validate($form, &$form_state) { */ function shortcut_link_edit_submit($form, &$form_state) { // Normalize the path in case it is an alias. - $form_state['values']['shortcut_link']['link_path'] = drupal_get_normal_path($form_state['values']['shortcut_link']['link_path']); + $form_state['values']['shortcut_link']['link_path'] = path()->getNormalPath($form_state['values']['shortcut_link']['link_path']); $shortcut_link = array_merge($form_state['values']['original_shortcut_link'], $form_state['values']['shortcut_link']); @@ -576,7 +576,7 @@ function shortcut_admin_add_link($shortcut_link, &$shortcut_set, $limit = NULL) } // Normalize the path in case it is an alias. - $shortcut_link['link_path'] = drupal_get_normal_path($shortcut_link['link_path']); + $shortcut_link['link_path'] = path()->getNormalPath($shortcut_link['link_path']); // Add the link to the end of the list. $shortcut_set->links[] = $shortcut_link; diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index be29dce..79ec35f 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -613,7 +613,7 @@ function shortcut_set_title_exists($title) { */ function shortcut_valid_link($path) { // Do not use URL aliases. - $normal_path = drupal_get_normal_path($path); + $normal_path = path()->getNormalPath($path); if ($path != $normal_path) { $path = $normal_path; } diff --git a/core/modules/statistics/statistics.module b/core/modules/statistics/statistics.module index ef1bceb..84cb72f 100644 --- a/core/modules/statistics/statistics.module +++ b/core/modules/statistics/statistics.module @@ -386,7 +386,7 @@ function statistics_block_view($delta = '') { * A string as a link, truncated to the width, linked to the given $path. */ function _statistics_link($path, $width = 35) { - $title = drupal_get_path_alias($path); + $title = path()->getPathAlias($path); $title = truncate_utf8($title, $width, FALSE, TRUE); return l($title, $path); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/LookupTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/LookupTest.php index a90b5f4..9b3f485 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/LookupTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/LookupTest.php @@ -10,19 +10,19 @@ namespace Drupal\system\Tests\Path; use Drupal\simpletest\WebTestBase; /** - * Unit test for drupal_lookup_path(). + * Tests for DrupalPathRegistry. */ class LookupTest extends WebTestBase { public static function getInfo() { return array( 'name' => t('Path lookup'), - 'description' => t('Tests that drupal_lookup_path() returns correct paths.'), + 'description' => t('Tests that DrupalPathRegistry returns correct paths.'), 'group' => t('Path API'), ); } /** - * Test that drupal_lookup_path() returns the correct path. + * Test that DrupalPathRegistry returns the correct path. */ function testDrupalLookupPath() { $account = $this->drupalCreateUser(); @@ -35,9 +35,9 @@ class LookupTest extends WebTestBase { 'source' => "user/$uid", 'alias' => 'foo', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Basic alias lookup works.')); - $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Basic source lookup works.')); + path()->save($path); + $this->assertEqual(path()->getPathAlias($path['source']), $path['alias'], t('Basic alias lookup works.')); + $this->assertEqual(path()->getNormalPath($path['alias']), $path['source'], t('Basic source lookup works.')); // Create a language specific alias for the default language (English). $path = array( @@ -45,17 +45,17 @@ class LookupTest extends WebTestBase { 'alias' => "users/$name", 'langcode' => 'en', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.')); - $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('English source overrides language-neutral source.')); + path()->save($path); + $this->assertEqual(path()->getPathAlias($path['source']), $path['alias'], t('English alias overrides language-neutral alias.')); + $this->assertEqual(path()->getNormalPath($path['alias']), $path['source'], t('English source overrides language-neutral source.')); // Create a language-neutral alias for the same path, again. $path = array( 'source' => "user/$uid", 'alias' => 'bar', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.')); + path()->save($path); + $this->assertEqual(path()->getPathAlias($path['source']), "users/$name", t('English alias still returned after entering a language-neutral alias.')); // Create a language-specific (xx-lolspeak) alias for the same path. $path = array( @@ -63,10 +63,10 @@ class LookupTest extends WebTestBase { 'alias' => 'LOL', 'langcode' => 'xx-lolspeak', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.')); + path()->save($path); + $this->assertEqual(path()->getPathAlias($path['source']), "users/$name", t('English alias still returned after entering a LOLspeak alias.')); // The LOLspeak alias should be returned if we really want LOLspeak. - $this->assertEqual(drupal_lookup_path('alias', $path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to drupal_lookup_path().')); + $this->assertEqual(path()->getPathAlias($path['source'], 'xx-lolspeak'), 'LOL', t('LOLspeak alias returned if we specify xx-lolspeak to DrupalPathRegistry.')); // Create a new alias for this path in English, which should override the // previous alias for "user/$uid". @@ -75,17 +75,17 @@ class LookupTest extends WebTestBase { 'alias' => 'users/my-new-path', 'langcode' => 'en', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.')); - $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Recently created English source returned.')); + path()->save($path); + $this->assertEqual(path()->getPathAlias($path['source']), $path['alias'], t('Recently created English alias returned.')); + $this->assertEqual(path()->getNormalPath($path['alias']), $path['source'], t('Recently created English source returned.')); // Remove the English aliases, which should cause a fallback to the most // recently created language-neutral alias, 'bar'. db_delete('url_alias') ->condition('langcode', 'en') ->execute(); - drupal_clear_path_cache(); - $this->assertEqual(drupal_lookup_path('alias', $path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.')); + path()->cacheClear(); + $this->assertEqual(path()->getPathAlias($path['source']), 'bar', t('Path lookup falls back to recently created language-neutral alias.')); // Test the situation where the alias and language are the same, but // the source differs. The newer alias record should be returned. @@ -94,7 +94,7 @@ class LookupTest extends WebTestBase { 'source' => 'user/' . $account2->uid, 'alias' => 'bar', ); - path_save($path); + path()->save($path); $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NOT_SPECIFIED paths with the same alias.')); } } diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/SaveTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/SaveTest.php index a34b384..218fd88 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/SaveTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/SaveTest.php @@ -10,13 +10,13 @@ namespace Drupal\system\Tests\Path; use Drupal\simpletest\WebTestBase; /** - * Tests the path_save() function. + * Tests the path()->save() function. */ class SaveTest extends WebTestBase { public static function getInfo() { return array( 'name' => t('Path save'), - 'description' => t('Tests that path_save() exposes the previous alias value.'), + 'description' => t('Tests that path()->save() exposes the previous alias value.'), 'group' => t('Path API'), ); } @@ -28,7 +28,7 @@ class SaveTest extends WebTestBase { } /** - * Tests that path_save() makes the original path available to modules. + * Tests that path()->save() makes the original path available to modules. */ function testDrupalSaveOriginalPath() { $account = $this->drupalCreateUser(); @@ -41,11 +41,11 @@ class SaveTest extends WebTestBase { 'alias' => 'foo', ); $path_original = $path; - path_save($path); + path()->save($path); // Alter the path. $path['alias'] = 'bar'; - path_save($path); + path()->save($path); // Test to see if the original alias is available to modules during // hook_path_update(). diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php index 9188b02..2de0c12 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/UrlAlterFunctionalTest.php @@ -41,7 +41,7 @@ class UrlAlterFunctionalTest extends WebTestBase { // Test that a path always uses its alias. $path = array('source' => "user/$uid/test1", 'alias' => 'alias/test1'); - path_save($path); + path()->save($path); $this->assertUrlInboundAlter('alias/test1', "user/$uid/test1"); $this->assertUrlOutboundAlter("user/$uid/test1", 'alias/test1'); @@ -114,7 +114,7 @@ class UrlAlterFunctionalTest extends WebTestBase { * * @param $original * A string with the aliased or un-normal path that is run through - * drupal_get_normal_path(). + * path()->getNormalPath(). * @param $final * A string with the expected result after url(). * @return @@ -122,7 +122,7 @@ class UrlAlterFunctionalTest extends WebTestBase { */ protected function assertUrlInboundAlter($original, $final) { // Test inbound altering. - $result = drupal_get_normal_path($original); + $result = path()->getNormalPath($original); $this->assertIdentical($result, $final, t('Altered inbound URL %original, expected %final, and got %result.', array('%original' => $original, '%final' => $final, '%result' => $result))); } } diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc index da54c96..47cf5f3 100644 --- a/core/modules/system/system.admin.inc +++ b/core/modules/system/system.admin.inc @@ -1493,10 +1493,11 @@ function system_site_information_settings() { '#type' => 'fieldset', '#title' => t('Front page'), ); + $front_page = variable_get('site_frontpage') != 'user' ? path()->getPathAlias(variable_get('site_frontpage')) : ''; $form['front_page']['site_frontpage'] = array( '#type' => 'textfield', '#title' => t('Default front page'), - '#default_value' => (variable_get('site_frontpage') != 'user' ? drupal_get_path_alias(variable_get('site_frontpage', 'user')) : ''), + '#default_value' => $front_page, '#size' => 40, '#description' => t('Optionally, specify a relative URL to display as the front page. Leave blank to display the default content feed.'), '#field_prefix' => url(NULL, array('absolute' => TRUE)), @@ -1538,7 +1539,7 @@ function system_site_information_settings_validate($form, &$form_state) { } else { // Get the normal path of the front page. - form_set_value($form['front_page']['site_frontpage'], drupal_get_normal_path($form_state['values']['site_frontpage']), $form_state); + form_set_value($form['front_page']['site_frontpage'], path()->getNormalPath($form_state['values']['site_frontpage']), $form_state); } // Validate front page path. if (!drupal_valid_path($form_state['values']['site_frontpage'])) { @@ -1546,10 +1547,10 @@ function system_site_information_settings_validate($form, &$form_state) { } // Get the normal paths of both error pages. if (!empty($form_state['values']['site_403'])) { - form_set_value($form['error_page']['site_403'], drupal_get_normal_path($form_state['values']['site_403']), $form_state); + form_set_value($form['error_page']['site_403'], path()->getNormalPath($form_state['values']['site_403']), $form_state); } if (!empty($form_state['values']['site_404'])) { - form_set_value($form['error_page']['site_404'], drupal_get_normal_path($form_state['values']['site_404']), $form_state); + form_set_value($form['error_page']['site_404'], path()->getNormalPath($form_state['values']['site_404']), $form_state); } // Validate 403 error path. if (!empty($form_state['values']['site_403']) && !drupal_valid_path($form_state['values']['site_403'])) { diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index f7a0e35..e6d1e29 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -3718,7 +3718,7 @@ function hook_system_themes_page_alter(&$theme_groups) { * @param $path_language * The language of the path. * - * @see drupal_get_normal_path() + * @see DrupalPathRegistry::getNormalPath() */ function hook_url_inbound_alter(&$path, $original_path, $path_language) { // Create the path user/me/edit, which allows a user to edit their account. diff --git a/core/scripts/generate-d7-content.sh b/core/scripts/generate-d7-content.sh index 7f03846..55efa7d 100644 --- a/core/scripts/generate-d7-content.sh +++ b/core/scripts/generate-d7-content.sh @@ -253,7 +253,7 @@ for ($i = 0; $i < 12; $i++) { 'alias' => "content/poll/$i/results", 'source' => "node/$node->nid/results", ); - path_save($path); + path()->save($path); // Add some votes $node = node_load($node->nid);