Commit 1b6ba524 authored by Dries's avatar Dries

- Patch #1357912 by Gábor Hojtsy, sun: convert path language code schema to langcode.

parent 7ef099f5
This diff is collapsed.
......@@ -103,6 +103,26 @@ function update_prepare_d8_bootstrap() {
if ($has_required_schema) {
// Update the environment for the language bootstrap if needed.
update_prepare_d8_language();
// Change language column to langcode in url_alias.
if (db_table_exists('url_alias') && db_field_exists('url_alias', 'language')) {
db_drop_index('url_alias', 'alias_language_pid');
db_drop_index('url_alias', 'source_language_pid');
$langcode_spec = array(
'description' => "The language code this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
);
$langcode_indexes = array('indexes' =>
array(
'alias_langcode_pid' => array('alias', 'langcode', 'pid'),
'source_langcode_pid' => array('source', 'langcode', 'pid'),
),
);
db_change_field('url_alias', 'language', 'langcode', $langcode_spec, $langcode_indexes);
}
}
}
}
......
......@@ -1654,7 +1654,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
$edit = array(
'source' => 'node/' . $node->nid,
'alias' => $english_path,
'language' => 'en',
'langcode' => 'en',
);
$this->drupalPost($path, $edit, t('Save'));
......@@ -1663,7 +1663,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
$edit = array(
'source' => 'node/' . $node->nid,
'alias' => $custom_language_path,
'language' => $langcode,
'langcode' => $langcode,
);
$this->drupalPost($path, $edit, t('Save'));
......@@ -1682,7 +1682,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
$edit = array(
'source' => 'node/' . $node->nid,
'alias' => $custom_path,
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
);
path_save($edit);
$lookup_path = drupal_lookup_path('alias', 'node/' . $node->nid, 'en');
......@@ -1700,7 +1700,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
$edit = array(
'source' => 'node/' . $first_node->nid,
'alias' => $custom_path,
'language' => 'en',
'langcode' => 'en',
);
path_save($edit);
......@@ -1708,7 +1708,7 @@ class LocalePathFunctionalTest extends DrupalWebTestCase {
$edit = array(
'source' => 'node/' . $second_node->nid,
'alias' => $custom_path,
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
);
path_save($edit);
......
......@@ -15,14 +15,14 @@ function path_admin_overview($keys = NULL) {
// Add the filter form above the overview table.
$build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys);
// Enable language column if locale is enabled or if we have any alias with language
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', 0, 1, array(':language' => LANGUAGE_NONE))->fetchField();
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE langcode <> :langcode', 0, 1, array(':langcode' => LANGUAGE_NONE))->fetchField();
$multilanguage = (module_exists('locale') || $alias_exists);
$header = array();
$header[] = array('data' => t('Alias'), 'field' => 'alias', 'sort' => 'asc');
$header[] = array('data' => t('System'), 'field' => 'source');
if ($multilanguage) {
$header[] = array('data' => t('Language'), 'field' => 'language');
$header[] = array('data' => t('Language'), 'field' => 'langcode');
}
$header[] = array('data' => t('Operations'));
......@@ -44,7 +44,7 @@ function path_admin_overview($keys = NULL) {
$row['data']['alias'] = l($data->alias, $data->source);
$row['data']['source'] = l($data->source, $data->source, array('alias' => TRUE));
if ($multilanguage) {
$row['data']['language'] = module_invoke('locale', 'language_name', $data->language);
$row['data']['langcode'] = module_invoke('locale', 'language_name', $data->langcode);
}
$operations = array();
......@@ -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 != drupal_get_path_alias($data->source, $data->langcode)) {
$row['class'] = array('warning');
}
......@@ -108,7 +108,7 @@ function path_admin_edit($path = array()) {
* @see path_admin_form_validate()
* @see path_admin_form_submit()
*/
function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'language' => LANGUAGE_NONE, 'pid' => NULL)) {
function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'langcode' => LANGUAGE_NONE, 'pid' => NULL)) {
$form['source'] = array(
'#type' => 'textfield',
'#title' => t('Existing system path'),
......@@ -132,19 +132,19 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali
// A hidden value unless locale module is enabled.
if (module_exists('locale')) {
$form['language'] = array(
$form['langcode'] = array(
'#type' => 'select',
'#title' => t('Language'),
'#options' => array(LANGUAGE_NONE => t('All languages')) + locale_language_list('name'),
'#default_value' => $path['language'],
'#default_value' => $path['langcode'],
'#weight' => -10,
'#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for <em>All languages</em>.'),
);
}
else {
$form['language'] = array(
$form['langcode'] = array(
'#type' => 'value',
'#value' => $path['language']
'#value' => $path['langcode']
);
}
......@@ -189,12 +189,12 @@ function path_admin_form_validate($form, &$form_state) {
$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.
$language = isset($form_state['values']['language']) ? $form_state['values']['language'] : LANGUAGE_NONE;
$langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LANGUAGE_NONE;
$has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND language = :language", array(
$has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND langcode = :langcode", array(
':pid' => $pid,
':alias' => $alias,
':language' => $language,
':langcode' => $langcode,
))
->fetchField();
......
......@@ -19,7 +19,7 @@
* - source: The internal system path.
* - alias: The URL alias.
* - pid: Unique path alias identifier.
* - language: The language of the alias.
* - langcode: The language code of the alias.
*
* @see path_save()
*/
......@@ -40,7 +40,7 @@ function hook_path_insert($path) {
* - source: The internal system path.
* - alias: The URL alias.
* - pid: Unique path alias identifier.
* - language: The language of the alias.
* - langcode: The language code of the alias.
*
* @see path_save()
*/
......@@ -59,7 +59,7 @@ function hook_path_update($path) {
* - source: The internal system path.
* - alias: The URL alias.
* - pid: Unique path alias identifier.
* - language: The language of the alias.
* - langcode: The language code of the alias.
*
* @see path_delete()
*/
......
......@@ -98,7 +98,7 @@ function path_form_node_form_alter(&$form, $form_state) {
if (!empty($form['#node']->nid)) {
$conditions = array('source' => 'node/' . $form['#node']->nid);
if ($form['#node']->language != LANGUAGE_NONE) {
$conditions['language'] = $form['#node']->language;
$conditions['langcode'] = $form['#node']->language;
}
$path = path_load($conditions);
if ($path === FALSE) {
......@@ -109,7 +109,7 @@ function path_form_node_form_alter(&$form, $form_state) {
'pid' => NULL,
'source' => isset($form['#node']->nid) ? 'node/' . $form['#node']->nid : NULL,
'alias' => '',
'language' => isset($form['#node']->language) ? $form['#node']->language : LANGUAGE_NONE,
'langcode' => isset($form['#node']->language) ? $form['#node']->language : LANGUAGE_NONE,
);
$form['path'] = array(
......@@ -140,7 +140,7 @@ function path_form_node_form_alter(&$form, $form_state) {
);
$form['path']['pid'] = array('#type' => 'value', '#value' => $path['pid']);
$form['path']['source'] = array('#type' => 'value', '#value' => $path['source']);
$form['path']['language'] = array('#type' => 'value', '#value' => $path['language']);
$form['path']['langcode'] = array('#type' => 'value', '#value' => $path['langcode']);
}
/**
......@@ -151,14 +151,14 @@ function path_form_element_validate($element, &$form_state, $complete_form) {
// Trim the submitted value.
$alias = trim($form_state['values']['path']['alias']);
form_set_value($element['alias'], $alias, $form_state);
// Node language (Locale module) needs special care. Since the language of
// the URL alias depends on the node language, and the node language can be
// switched right within the same form, we need to conditionally overload
// the originally assigned URL alias language.
// Node language needs special care. Since the language of the URL alias
// depends on the node language, and the node language can be switched
// right within the same form, we need to conditionally overload the
// originally assigned URL alias language.
// @todo Remove this after converting Path module to a field, and, after
// stopping Locale module from abusing the content language system.
if (isset($form_state['values']['language'])) {
form_set_value($element['language'], $form_state['values']['language'], $form_state);
form_set_value($element['langcode'], $form_state['values']['language'], $form_state);
}
$path = $form_state['values']['path'];
......@@ -166,7 +166,7 @@ function path_form_element_validate($element, &$form_state, $complete_form) {
// Ensure that the submitted alias does not exist yet.
$query = db_select('url_alias')
->condition('alias', $path['alias'])
->condition('language', $path['language']);
->condition('langcode', $path['langcode']);
if (!empty($path['source'])) {
$query->condition('source', $path['source'], '<>');
}
......@@ -189,7 +189,7 @@ function path_node_insert($node) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'node/' . $node->nid;
$path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
$path['langcode'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
path_save($path);
}
}
......@@ -210,7 +210,7 @@ function path_node_update($node) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'node/' . $node->nid;
$path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
$path['langcode'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
path_save($path);
}
}
......@@ -238,7 +238,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
'pid' => NULL,
'source' => isset($form['#term']['tid']) ? 'taxonomy/term/' . $form['#term']['tid'] : NULL,
'alias' => '',
'language' => LANGUAGE_NONE,
'langcode' => LANGUAGE_NONE,
);
$form['path'] = array(
'#access' => user_access('create url aliases') || user_access('administer url aliases'),
......@@ -255,7 +255,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
);
$form['path']['pid'] = array('#type' => 'value', '#value' => $path['pid']);
$form['path']['source'] = array('#type' => 'value', '#value' => $path['source']);
$form['path']['language'] = array('#type' => 'value', '#value' => $path['language']);
$form['path']['langcode'] = array('#type' => 'value', '#value' => $path['langcode']);
}
}
......@@ -270,7 +270,7 @@ function path_taxonomy_term_insert($term) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'taxonomy/term/' . $term->tid;
$path['language'] = LANGUAGE_NONE;
$path['langcode'] = LANGUAGE_NONE;
path_save($path);
}
}
......@@ -291,7 +291,7 @@ function path_taxonomy_term_update($term) {
if (!empty($path['alias'])) {
// Ensure fields for programmatic executions.
$path['source'] = 'taxonomy/term/' . $term->tid;
$path['language'] = LANGUAGE_NONE;
$path['langcode'] = LANGUAGE_NONE;
path_save($path);
}
}
......
......@@ -420,7 +420,7 @@ class PathLanguageUITestCase extends DrupalWebTestCase {
$edit = array();
$edit['source'] = 'admin/config/search/path';
$edit['alias'] = $name;
$edit['language'] = 'en';
$edit['langcode'] = 'en';
$this->drupalPost('admin/config/search/path/add', $edit, t('Save'));
$this->drupalGet($name);
......@@ -435,7 +435,7 @@ class PathLanguageUITestCase extends DrupalWebTestCase {
$edit = array();
$edit['source'] = 'admin/config/search/path';
$edit['alias'] = $name;
$edit['language'] = 'fr';
$edit['langcode'] = 'fr';
$this->drupalPost('admin/config/search/path/add', $edit, t('Save'));
$this->drupalGet('fr/' . $name);
......
......@@ -278,7 +278,7 @@ class PathLookupTest extends DrupalWebTestCase {
$path = array(
'source' => "user/$uid",
'alias' => "users/$name",
'language' => 'en',
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('English alias overrides language-neutral alias.'));
......@@ -296,7 +296,7 @@ class PathLookupTest extends DrupalWebTestCase {
$path = array(
'source' => "user/$uid",
'alias' => 'LOL',
'language' => 'xx-lolspeak',
'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.'));
......@@ -308,7 +308,7 @@ class PathLookupTest extends DrupalWebTestCase {
$path = array(
'source' => "user/$uid",
'alias' => 'users/my-new-path',
'language' => 'en',
'langcode' => 'en',
);
path_save($path);
$this->assertEqual(drupal_lookup_path('alias', $path['source']), $path['alias'], t('Recently created English alias returned.'));
......@@ -317,7 +317,7 @@ class PathLookupTest extends DrupalWebTestCase {
// 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')
->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.'));
......
......@@ -1592,8 +1592,8 @@ function system_schema() {
'not null' => TRUE,
'default' => '',
),
'language' => array(
'description' => "The language this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
'langcode' => array(
'description' => "The language code this alias is for; if 'und', the alias will be used for unknown languages. Each Drupal path can have an alias for each supported language.",
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
......@@ -1602,8 +1602,8 @@ function system_schema() {
),
'primary key' => array('pid'),
'indexes' => array(
'alias_language_pid' => array('alias', 'language', 'pid'),
'source_language_pid' => array('source', 'language', 'pid'),
'alias_langcode_pid' => array('alias', 'langcode', 'pid'),
'source_langcode_pid' => array('source', 'langcode', 'pid'),
),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment