From eb8c4c09a27a8c04defe5b696fd9d3d497f81b07 Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Thu, 8 Dec 2011 12:29:13 +0900 Subject: [PATCH] Issue #381994 by xjm, good_man, elcuco, et al: Fixed Machine-name fields are always in Latin characters, and should therefore always be LTR. --- core/includes/form.inc | 7 +++++++ core/modules/locale/locale.test | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/core/includes/form.inc b/core/includes/form.inc index aecf0daa3c3..87ae891321a 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -3355,6 +3355,13 @@ function form_process_machine_name($element, &$form_state) { 'replace' => '_', ); + // By default, machine names are restricted to Latin alphanumeric characters. + // So, default to LTR directionality. + if (!isset($element['#attributes'])) { + $element['#attributes'] = array(); + } + $element['#attributes'] += array('dir' => 'ltr'); + // The source element defaults to array('name'), but may have been overidden. if (empty($element['#machine_name']['source'])) { return $element; diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index 5c49be4ac0b..8ff85ed4b4e 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -1861,6 +1861,34 @@ class LocaleContentFunctionalTest extends DrupalWebTestCase { parent::setUp('locale'); } + /** + * Verifies that machine name fields are always LTR. + */ + function testMachineNameLTR() { + // User to add and remove language. + $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages')); + + // Log in as admin. + $this->drupalLogin($admin_user); + + // Verify that the machine name field is LTR for a new content type. + $this->drupalGet('admin/structure/types/add'); + $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when no additional language is configured.'); + + // Install the Arabic language (which is RTL) and configure as the default. + $edit = array(); + $edit['predefined_langcode'] = 'ar'; + $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); + + $edit = array(); + $edit['site_default'] = 'ar'; + $this->drupalPost(NULL, $edit, t('Save configuration')); + + // Verify that the machine name field is still LTR for a new content type. + $this->drupalGet('admin/structure/types/add'); + $this->assertFieldByXpath('//input[@name="type" and @dir="ltr"]', NULL, 'The machine name field is LTR when the default language is RTL.'); + } + /** * Test if a content type can be set to multilingual and language is present. */