Problem/Motivation

LanguageInterface::DIRECTION_RTL and LanguageInterface::DIRECTION_LTR
are a clear and useful constants.

BUT but they are not used in all places.

Most notably in Drupal\Core\Language\Language

public static $defaultValues = array(
    'id' => 'en',
    'name' => 'English',
    'direction' => 0,   <--- this should read self::DIRECTION_LTR
    'weight' => 0,
    'locked' => 0,
    'default' => TRUE,
  );

Proposed resolution

consistently use the constants a cursory search for " 'direction' => "

show that several files need to be updated. Language.php, ConfigOverrideWebTest, ConfigTranslationUiTest.php, LanguageDependancyInjecitonTest.php
and many more

Remaining tasks

A more exhaustive search for places where the constants should be used.
The fix is obvious.

User interface changes

none

API changes

none

Comments

martin107’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new13.05 KB

The following files were updated.

core/lib/Drupal/Core/Language/Language.php
core/modules/language/src/Tests/Condition/LanguageConditionTest.php
core/modules/language/src/Tests/LanguageDependencyInjectionTest.php
core/modules/language/src/Tests/LanguageListTest.php
core/modules/locale/src/Tests/LocaleConfigTranslationTest.php
core/modules/locale/src/Tests/LocaleContentTest.php
core/modules/locale/src/Tests/LocaleImportFunctionalTest.php
core/modules/locale/src/Tests/LocaleLocaleLookupTest.php
core/modules/locale/src/Tests/LocalePathTest.php
core/modules/locale/src/Tests/LocaleTranslationUiTest.php
core/modules/locale/src/Tests/LocaleUpdateTest.php
core/modules/system/src/Tests/Theme/TwigTransTest.php
core/modules/toolbar/src/Tests/ToolbarAdminMenuTest.php
core/modules/user/src/Tests/UserAdminLanguageTest.php
core/modules/user/src/Tests/UserLanguageTest.php

martin107’s picture

StatusFileSize
new14.52 KB
new1.47 KB

Found 2 more

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Awesome detective work, @martin107!

Nothing to complain.

Also shameless bump: #2070737: Change values of LanguageInterface::DIRECTION_(LTR/RTL) to ('ltr'/'rtl')

dries’s picture

Status: Reviewed & tested by the community » Fixed

Nice clean-up. Committed to 8.x. Thank you.

  • Dries committed d247620 on 8.x
    Issue #2286403 by martin107: Inconsistent use of magic number when...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.