diff --git a/includes/common.inc b/includes/common.inc index 5f7cdb8..46a79f1 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2146,7 +2146,7 @@ function url($path = NULL, array $options = array()) { } elseif (!empty($path) && !$options['alias']) { $language = isset($options['language']) && isset($options['language']->language) ? $options['language']->language : ''; - $alias = drupal_get_path_alias($original_path, $language); + $alias = path()->getPathAlias($original_path, $language); if ($alias != $original_path) { $path = $alias; } @@ -2485,7 +2485,7 @@ function drupal_deliver_html_page($page_callback_result) { $_GET['destination'] = $_GET['q']; } - $path = drupal_get_normal_path(variable_get('site_404', '')); + $path = path()->getNormalPath(variable_get('site_404', '')); if ($path && $path != $_GET['q']) { // Custom 404 handler. Set the active item in case there are tabs to // display, or other dependencies on the path. @@ -2514,7 +2514,7 @@ function drupal_deliver_html_page($page_callback_result) { $_GET['destination'] = $_GET['q']; } - $path = drupal_get_normal_path(variable_get('site_403', '')); + $path = path()->getNormalPath(variable_get('site_403', '')); if ($path && $path != $_GET['q']) { // Custom 403 handler. Set the active item in case there are tabs to // display or other dependencies on the path. diff --git a/includes/path.inc b/includes/path.inc index 630b34c..895e427 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -9,15 +9,196 @@ * executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);". */ +interface DrupalPathRegistryInterface { + /** + * 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. + * - language: (optional) The language of the alias. + */ + public function save(array &$path); + + /** + * Fetch a specific URL alias from the database. + * + * @param $conditions + * A string representing the source, a number representing the pid, or an + * array of query conditions. + * + * @return + * FALSE if no alias was found or an associative array containing the + * following keys: + * - source: The internal system path. + * - alias: The URL alias. + * - pid: Unique path alias identifier. + * - language: The language of the alias. + */ + public function load($conditions); + + /** + * Delete a URL alias. + * + * @param $criteria + * A number representing the pid or an array of criteria. + */ + public function delete($pid); + + /** + * Given a path alias, return the internal path it represents. + * + * @param $path + * A Drupal path alias. + * @param $path_language + * 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. + */ + public function getNormalPath($path, $path_language = NULL); + + /** + * 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 optional internal Drupal path. + * @param $path_language + * 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. + */ + public function getPathAlias($path = NULL, $path_language = NULL); + + /** + * Clear the path cache. + * + * @param $source + * An optional system path for which an alias is being changed. + */ + public function cacheClear($source = NULL); +} + +class DrupalPathRegistry implements DrupalPathRegistryInterface { + + public function save(array &$path) { + $path += array('pid' => 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 = $_GET['q']; + } + $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); + } +} + +/** + * Return a DrupalPathRegistryInterface class. + */ +function path() { + static $path_registry; + if ($path_registry === NULL) { + $class = variable_get('path_registry_class', 'DrupalPathRegistry'); + $path_registry = new $class(); + } + return $path_registry; +} + /** * Initialize the $_GET['q'] variable to the proper normal path. */ function drupal_path_initialize() { if (!empty($_GET['q'])) { - $_GET['q'] = drupal_get_normal_path($_GET['q']); + $_GET['q'] = path()->getNormalPath($_GET['q']); } else { - $_GET['q'] = drupal_get_normal_path(variable_get('site_frontpage', 'node')); + $_GET['q'] = path()->getNormalPath(variable_get('site_frontpage', 'node')); } } @@ -125,7 +306,7 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { if (isset($cache['map'][$path_language][$path])) { return $cache['map'][$path_language][$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, '/')])) { @@ -218,64 +399,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 $path_language - * 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, $path_language = NULL) { - // If no path is specified, use the current page's path. - if ($path == NULL) { - $path = $_GET['q']; - } - $result = $path; - if ($alias = drupal_lookup_path('alias', $path, $path_language)) { - $result = $alias; - } - return $result; -} - -/** - * Given a path alias, return the internal path it represents. - * - * @param $path - * A Drupal path alias. - * @param $path_language - * 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, $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; -} - -/** * Check if the current page is the front page. * * @return @@ -386,11 +509,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 @@ -400,72 +522,8 @@ function drupal_path_alias_whitelist_rebuild($source = NULL) { * - pid: Unique path alias identifier. * - language: The language 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. - * - language: (optional) The language of the alias. - */ -function path_save(&$path) { - $path += array('pid' => 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); - } - 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); } /** @@ -568,14 +626,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/modules/block/block.module b/modules/block/block.module index 920090f..05f87ca 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -802,7 +802,7 @@ function block_block_list_alter(&$blocks) { $pages = drupal_strtolower($block->pages); if ($block->visibility < BLOCK_VISIBILITY_PHP) { // Convert the Drupal path to lowercase - $path = drupal_strtolower(drupal_get_path_alias($_GET['q'])); + $path = drupal_strtolower(path()->getPathAlias($_GET['q'])); // Compare the lowercase internal and lowercase path alias (if any). $page_match = drupal_match_path($path, $pages); if ($path != $_GET['q']) { diff --git a/modules/locale/locale.test b/modules/locale/locale.test index b94f565..af3d1c4 100644 --- a/modules/locale/locale.test +++ b/modules/locale/locale.test @@ -1754,13 +1754,13 @@ class LocalePathFunctionalTest extends DrupalWebTestCase { 'alias' => $custom_path, 'language' => LANGUAGE_NONE, ); - 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' => 'article', 'promote' => 1)); @@ -1772,7 +1772,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase { 'alias' => $custom_path, 'language' => 'en', ); - path_save($edit); + path()->save($edit); // Assign a custom path alias to second node with LANGUAGE_NONE. $edit = array( @@ -1780,7 +1780,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase { 'alias' => $custom_path, 'language' => LANGUAGE_NONE, ); - path_save($edit); + path()->save($edit); // Test that both node titles link to our path alias. $this->drupalGet(''); diff --git a/modules/menu/menu.admin.inc b/modules/menu/menu.admin.inc index 8669c33..11a3cf5 100644 --- a/modules/menu/menu.admin.inc +++ b/modules/menu/menu.admin.inc @@ -357,7 +357,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/modules/path/path.admin.inc b/modules/path/path.admin.inc index c8a6963..cd5f869 100644 --- a/modules/path/path.admin.inc +++ b/modules/path/path.admin.inc @@ -68,7 +68,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->language)) { + if ($data->alias != path()->getPathAlias($data->source, $data->language)) { $row['class'] = array('warning'); } @@ -185,7 +185,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 locale module is enabled, otherwise save for all languages. @@ -213,7 +213,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'; @@ -240,7 +240,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/modules/path/path.module b/modules/path/path.module index 332287d..0e3076a 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -100,7 +100,7 @@ function path_form_node_form_alter(&$form, $form_state) { if ($form['#node']->language != LANGUAGE_NONE) { $conditions['language'] = $form['#node']->language; } - $path = path_load($conditions); + $path = path()->load($conditions); if ($path === FALSE) { $path = array(); } @@ -190,7 +190,7 @@ function path_node_insert($node) { // Ensure fields for programmatic executions. $path['source'] = 'node/' . $node->nid; $path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE; - path_save($path); + path()->save($path); } } } @@ -204,14 +204,14 @@ function path_node_update($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['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE; - path_save($path); + path()->save($path); } } } @@ -221,7 +221,7 @@ function path_node_update($node) { */ function path_node_delete($node) { // Delete all aliases associated with this node. - path_delete(array('source' => 'node/' . $node->nid)); + path()->delete(array('source' => 'node/' . $node->nid)); } /** @@ -230,7 +230,7 @@ function path_node_delete($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(); } @@ -271,7 +271,7 @@ function path_taxonomy_term_insert($term) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; $path['language'] = LANGUAGE_NONE; - path_save($path); + path()->save($path); } } } @@ -285,14 +285,14 @@ function path_taxonomy_term_update($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['language'] = LANGUAGE_NONE; - path_save($path); + path()->save($path); } } } @@ -302,5 +302,5 @@ function path_taxonomy_term_update($term) { */ function path_taxonomy_term_delete($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/modules/path/path.test b/modules/path/path.test index 8f0406e..cf332f0 100644 --- a/modules/path/path.test +++ b/modules/path/path.test @@ -79,7 +79,7 @@ class PathTestCase extends DrupalWebTestCase { $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.'); @@ -287,7 +287,7 @@ class PathLanguageTestCase extends DrupalWebTestCase { $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"]); @@ -324,7 +324,7 @@ class PathLanguageTestCase extends DrupalWebTestCase { // 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.'); @@ -348,20 +348,20 @@ class PathLanguageTestCase extends DrupalWebTestCase { $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->language); + 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->language); + $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->language); + $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->language); + $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/modules/search/search.module b/modules/search/search.module index 5844f6e..2abda81 100644 --- a/modules/search/search.module +++ b/modules/search/search.module @@ -637,7 +637,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/modules/shortcut/shortcut.admin.inc b/modules/shortcut/shortcut.admin.inc index 75c12b4..9f7b624 100644 --- a/modules/shortcut/shortcut.admin.inc +++ b/modules/shortcut/shortcut.admin.inc @@ -471,7 +471,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; @@ -518,7 +518,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']); @@ -574,7 +574,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/modules/shortcut/shortcut.module b/modules/shortcut/shortcut.module index f8ddcc2..1c44aa4 100644 --- a/modules/shortcut/shortcut.module +++ b/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/modules/shortcut/shortcut.test b/modules/shortcut/shortcut.test index 322c63f..dca530d 100644 --- a/modules/shortcut/shortcut.test +++ b/modules/shortcut/shortcut.test @@ -120,7 +120,7 @@ class ShortcutLinksTestCase extends ShortcutTestCase { 'source' => 'node/' . $this->node->nid, 'alias' => $this->randomName(8), ); - path_save($path); + path()->save($path); // Create some paths to test. $test_cases = array( @@ -141,7 +141,7 @@ class ShortcutLinksTestCase extends ShortcutTestCase { $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/modules/simpletest/tests/path.test b/modules/simpletest/tests/path.test index 82598b5..7a8eaa5 100644 --- a/modules/simpletest/tests/path.test +++ b/modules/simpletest/tests/path.test @@ -158,7 +158,7 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { // 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'); @@ -223,7 +223,7 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { * * @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 @@ -231,25 +231,25 @@ class UrlAlterFunctionalTest extends DrupalWebTestCase { */ 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))); } } /** - * Unit test for drupal_lookup_path(). + * Tests for DrupalPathRegistry. */ class PathLookupTest extends DrupalWebTestCase { 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(); @@ -262,9 +262,9 @@ class PathLookupTest extends DrupalWebTestCase { '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( @@ -272,17 +272,17 @@ class PathLookupTest extends DrupalWebTestCase { 'alias' => "users/$name", 'language' => '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( @@ -290,10 +290,10 @@ class PathLookupTest extends DrupalWebTestCase { 'alias' => 'LOL', 'language' => '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". @@ -302,17 +302,17 @@ class PathLookupTest extends DrupalWebTestCase { 'alias' => 'users/my-new-path', 'language' => '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('language', '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. @@ -321,7 +321,7 @@ class PathLookupTest extends DrupalWebTestCase { 'source' => 'user/' . $account2->uid, 'alias' => 'bar', ); - path_save($path); - $this->assertEqual(drupal_lookup_path('source', $path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NONE paths with the same alias.')); + path()->save($path); + $this->assertEqual(path()->getNormalPath($path['alias']), $path['source'], t('Newer alias record is returned when comparing two LANGUAGE_NONE paths with the same alias.')); } } diff --git a/modules/statistics/statistics.module b/modules/statistics/statistics.module index 0ba9d7f..c677828 100644 --- a/modules/statistics/statistics.module +++ b/modules/statistics/statistics.module @@ -375,7 +375,7 @@ function statistics_block_view($delta = '') { * statistics module. */ 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/modules/system/system.admin.inc b/modules/system/system.admin.inc index b08f418..808971d 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1475,10 +1475,11 @@ function system_site_information_settings() { '#type' => 'fieldset', '#title' => t('Front page'), ); + $front_page = variable_get('site_frontpage') != 'node' ? 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')!='node'?drupal_get_path_alias(variable_get('site_frontpage', 'node')):''), + '#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)) . (variable_get('clean_url', 0) ? '' : '?q='), @@ -1531,7 +1532,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'])) { @@ -1539,10 +1540,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/scripts/generate-d7-content.sh b/scripts/generate-d7-content.sh index e65c099..d002f95 100644 --- a/scripts/generate-d7-content.sh +++ b/scripts/generate-d7-content.sh @@ -242,7 +242,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);