diff --git a/core/includes/theme.inc b/core/includes/theme.inc index f136ca1..cae7172 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1799,7 +1799,6 @@ function template_preprocess_page(&$variables) { $variables['base_path'] = base_path(); $variables['front_page'] = \Drupal::url(''); $variables['language'] = $language_interface; - $variables['language']->dir = $language_interface->direction ? 'rtl' : 'ltr'; $variables['logo'] = theme_get_setting('logo.url'); $variables['site_name'] = (theme_get_setting('features.name') ? String::checkPlain($site_config->get('name')) : ''); $variables['site_slogan'] = (theme_get_setting('features.slogan') ? Xss::filterAdmin($site_config->get('slogan')) : ''); diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index b04f60f..36d16ab 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -50,7 +50,7 @@ class Language implements LanguageInterface { * * @var int */ - public $direction = self::DIRECTION_LTR; + protected $direction = self::DIRECTION_LTR; /** * The weight, used for ordering languages in lists, like selects or tables. diff --git a/core/lib/Drupal/Core/Language/LanguageInterface.php b/core/lib/Drupal/Core/Language/LanguageInterface.php index 5f5ff24..4ab4f9a 100644 --- a/core/lib/Drupal/Core/Language/LanguageInterface.php +++ b/core/lib/Drupal/Core/Language/LanguageInterface.php @@ -89,12 +89,12 @@ /** * Language written left to right. Possible value of $language->direction. */ - const DIRECTION_LTR = 0; + const DIRECTION_LTR = 'ltr'; /** * Language written right to left. Possible value of $language->direction. */ - const DIRECTION_RTL = 1; + const DIRECTION_RTL = 'rtl'; /** * Gets the name of the language. @@ -115,7 +115,7 @@ public function getId(); /** * Gets the text direction (left-to-right or right-to-left). * - * @return int + * @return string * Either self::DIRECTION_LTR or self::DIRECTION_RTL. */ public function getDirection(); diff --git a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php index 164f7f5..b544897 100644 --- a/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php +++ b/core/lib/Drupal/Core/Page/DefaultHtmlFragmentRenderer.php @@ -101,7 +101,7 @@ public function preparePage(HtmlPage $page, &$page_array) { $language_interface = $this->languageManager->getCurrentLanguage(); $html_attributes = $page->getHtmlAttributes(); $html_attributes['lang'] = $language_interface->id; - $html_attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; + $html_attributes['dir'] = $language_interface->getDirection(); $this->setDefaultMetaTags($page); diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 5fd5d21..7d96e4d 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -467,13 +467,13 @@ function template_preprocess_book_export_html(&$variables) { $variables['title'] = String::checkPlain($variables['title']); $variables['base_url'] = $base_url; $variables['language'] = $language_interface; - $variables['language_rtl'] = ($language_interface->direction == LanguageInterface::DIRECTION_RTL); + $variables['language_rtl'] = ($language_interface->getDirection() == LanguageInterface::DIRECTION_RTL); $variables['head'] = drupal_get_html_head(); // HTML element attributes. $attributes = array(); $attributes['lang'] = $language_interface->id; - $attributes['dir'] = $language_interface->direction ? 'rtl' : 'ltr'; + $attributes['dir'] = $language_interface->getDirection(); $variables['html_attributes'] = new Attribute($attributes); } diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index 220ec77..074fffa 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -7,6 +7,7 @@ use Drupal\Core\Template\Attribute; use Drupal\Component\Utility\SafeMarkup; +use Drupal\Core\Language\LanguageInterface; /** * Prepares variables for CKEditor settings toolbar templates. @@ -19,9 +20,7 @@ * - plugins: A list of plugins. */ function template_preprocess_ckeditor_settings_toolbar(&$variables) { - // Simplify the language direction information for toolbar buttons. $language_interface = \Drupal::languageManager()->getCurrentLanguage(); - $language_direction = $language_interface->direction ? 'rtl' : 'ltr'; // Create lists of active and disabled buttons. $editor = $variables['editor']; @@ -61,7 +60,7 @@ function template_preprocess_ckeditor_settings_toolbar(&$variables) { } $disabled_buttons = array_diff_key($buttons, $multiple_buttons); - $rtl = $language_direction === 'rtl' ? '_rtl' : ''; + $rtl = $language_interface->getDirection() === LanguageInterface::DIRECTION_RTL ? '_rtl' : ''; $build_button_item = function($button, $rtl) { // Value of the button item. diff --git a/core/modules/language/config/install/language.entity.en.yml b/core/modules/language/config/install/language.entity.en.yml index 540be65..34b6c29 100644 --- a/core/modules/language/config/install/language.entity.en.yml +++ b/core/modules/language/config/install/language.entity.en.yml @@ -1,6 +1,6 @@ id: en label: English -direction: 0 +direction: 'ltr' weight: 0 locked: false status: true diff --git a/core/modules/language/config/install/language.entity.und.yml b/core/modules/language/config/install/language.entity.und.yml index d813c60..67caf48 100644 --- a/core/modules/language/config/install/language.entity.und.yml +++ b/core/modules/language/config/install/language.entity.und.yml @@ -1,6 +1,6 @@ id: und label: 'Not specified' -direction: 0 +direction: 'ltr' weight: 1 locked: true status: true diff --git a/core/modules/language/config/install/language.entity.zxx.yml b/core/modules/language/config/install/language.entity.zxx.yml index 3ae26a9..7f02cf7 100644 --- a/core/modules/language/config/install/language.entity.zxx.yml +++ b/core/modules/language/config/install/language.entity.zxx.yml @@ -1,6 +1,6 @@ id: zxx label: 'Not applicable' -direction: 0 +direction: 'ltr' weight: 2 locked: true status: true diff --git a/core/modules/language/config/schema/language.schema.yml b/core/modules/language/config/schema/language.schema.yml index 210a1e6..2633fdc 100644 --- a/core/modules/language/config/schema/language.schema.yml +++ b/core/modules/language/config/schema/language.schema.yml @@ -92,7 +92,7 @@ language.entity.*: type: label label: 'Label' direction: - type: integer + type: string label: 'Direction' weight: type: integer diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index 1235b8a..1dff869 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -64,7 +64,7 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu * * @var integer */ - public $direction = ''; + protected $direction = self::DIRECTION_LTR; /** * The weight of the language, used in lists of languages. diff --git a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php index 529ceab..7fc129e 100644 --- a/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php +++ b/core/modules/language/src/Tests/LanguageCustomLanguageConfigurationTest.php @@ -43,7 +43,7 @@ public function testLanguageConfiguration() { $this->assertText(t('!name field is required.', array('!name' => t('Language code')))); $this->assertText(t('!name field is required.', array('!name' => t('Language name in English')))); $empty_language = new Language(); - $this->assertFieldChecked('edit-direction-' . $empty_language->direction, 'Consistent usage of language direction.'); + $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.'); $this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.'); // Test validation of invalid values. diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index a6b785e..474de4c 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -555,7 +555,7 @@ function locale_library_alter(array &$library, $name) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $settings['jquery']['ui']['datepicker'] = array( - 'isRTL' => $language_interface->direction == LanguageInterface::DIRECTION_RTL, + 'isRTL' => $language_interface->getDirection() == LanguageInterface::DIRECTION_RTL, 'firstDay' => \Drupal::config('system.date')->get('first_day'), ); $library['js'][] = array( @@ -737,11 +737,10 @@ function locale_preprocess_node(&$variables) { // add markup to identify the language. Otherwise the page language is // inherited. $variables['attributes']['lang'] = $node_language->id; - if ($node_language->direction != $language_interface->direction) { + if ($node_language->getDirection() != $language_interface->getDirection()) { // If text direction is different form the page's text direction, add // direction information as well. - $dir = array('ltr', 'rtl'); - $variables['attributes']['dir'] = $dir[$node_language->direction]; + $variables['attributes']['dir'] = $node_language->getDirection(); } } } diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index ebe1b15..c331e67 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -247,7 +247,7 @@ function hook_library_alter(array &$library, $name) { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); $settings['jquery']['ui']['datepicker'] = array( - 'isRTL' => $language_interface->direction == LanguageInterface::DIRECTION_RTL, + 'isRTL' => $language_interface->getDirection() == LanguageInterface::DIRECTION_RTL, 'firstDay' => \Drupal::config('system.date')->get('first_day'), ); $library['js'][] = array(