Problem/Motivation

#2226533: Changes to the Language class due to the LanguageInterface (followup) is making properties protected and was

diff --git a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
index 635633c..ae38d65 100644
--- a/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
+++ b/core/modules/language/src/Tests/LanguageConfigurationElementTest.php
@@ -78,17 +78,17 @@ public function testDefaultLangcode() {
// Site's default.
$old_default = \Drupal::languageManager()->getDefaultLanguage();
// Ensure the language entity default value is correct.
$configurable_language = entity_load('configurable_language', $old_default->getId());
$this->assertTrue($configurable_language->get('default'), 'The en language entity is flagged as the default language.');
- $old_default->default = FALSE;
+ $old_default->setDefault(FALSE);
language_save($old_default);
$new_default = \Drupal::languageManager()->getLanguage('cc');
- $new_default->default = TRUE;
+ $new_default->setDefault(TRUE);
language_save($new_default);
language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'site_default', 'language_show' => TRUE));
$langcode = language_get_default_langcode('custom_type', 'custom_bundle');

but #2334763: Tidy up of LanguageInterface - removal of setters and other unnecessary methods is taking out the setDefault

Proposed resolution

Remaining tasks

User interface changes

No.

API changes

No.

Comments

YesCT’s picture

Issue summary: View changes
rpayanm’s picture

Status: Active » Needs review
FileSize
1.14 KB
martin107’s picture

We have a stale remnant from a previous reroll... or something

Can someone from the D8MI team ok the removal of the duplicate test file?

https://www.drupal.org/node/2337989

martin107’s picture

@rpayanm.. Hi

What you have done is appropriate, but may I suggest a different approach.

When I look at #2334763: Tidy up of LanguageInterface - removal of setters and other unnecessary methods I see one of the wanted API changes is

Removal of all setters from Language and ConfigurableLanguage

Can I outline a solution that does not used setters and getters but uses new Language() statement to specify what default values to override
Here is a code fragment that I think will work

public function testDefaultLangcode() {
     // Ensure the language entity default value is correct.
     $configurable_language = entity_load('configurable_language', $old_default->getId());
     $this->assertTrue($configurable_language->get('default'), 'The en language entity is flagged as the default language.');
-    $old_default->default = FALSE;
-    language_save($old_default);
-    $new_default = \Drupal::languageManager()->getLanguage('cc');
-    $new_default->default = TRUE;
+    $updateLanguage = new Language(['langcode' => 'en', 'default' => FALSE] );
+    language_save($updateLanguage);
+    $new_default  = new Language(['langcode' => 'cc', 'default' => TRUE]);
     language_save($new_default);
     language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'site_default', 'language_show' => TRUE));
     $langcode = language_get_default_langcode('custom_type', 'custom_bundle');
martin107’s picture

Status: Needs review » Closed (works as designed)

core now reflects @rpayanm, solution with a minor alteration

setDefault now looks like this..

$new_default = ConfigurableLanguage::load('cc');
$new_default->set('default', TRUE);
$new_default->save();