Commit 4f776f6f authored by alexpott's avatar alexpott

Issue #2407125 by Cogax, vijaycs85, Gábor Hojtsy: LanguageInterface should not support setName

parent b9819faa
......@@ -105,15 +105,6 @@ public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->name = $name;
return $this;
}
/**
* {@inheritdoc}
*/
......
......@@ -109,16 +109,6 @@ interface LanguageInterface {
*/
public function getName();
/**
* Sets the name of the language.
*
* @param string $name
* The human-readable English name of the language.
*
* @return $this
*/
public function setName($name);
/**
* Gets the ID (language code).
*
......
......@@ -397,9 +397,19 @@ protected function filterLanguages(array $languages, $flags = LanguageInterface:
$filtered_languages = array();
// Add the site's default language if requested.
if ($flags & LanguageInterface::STATE_SITE_DEFAULT) {
// Setup a language to have the defaults, but with overridden name.
$default = $this->getDefaultLanguage();
$default->setName($this->t("Site's default language (@lang_name)", array('@lang_name' => $default->getName())));
// Setup a language to have the defaults with data appropriate of the
// default language only for runtime.
$defaultLanguage = $this->getDefaultLanguage();
$default = new Language(
array(
'id' => $defaultLanguage->getId(),
'name' => $this->t("Site's default language (@lang_name)",
array('@lang_name' => $defaultLanguage->getName())),
'direction' => $defaultLanguage->getDirection(),
'weight' => $defaultLanguage->getWeight(),
)
);
$filtered_languages[LanguageInterface::LANGCODE_SITE_DEFAULT] = $default;
}
......
......@@ -16,6 +16,16 @@
*/
interface ConfigurableLanguageInterface extends ConfigEntityInterface, LanguageInterface {
/**
* Sets the name of the language.
*
* @param string $name
* The human-readable English name of the language.
*
* @return $this
*/
public function setName($name);
/**
* Sets the weight of the language.
*
......
<?php
/**
* @file
* Contains \Drupal\Tests\language\ConfigurableLanguageTest.
*/
namespace Drupal\Tests\language;
use Drupal\simpletest\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
/**
* Tests the ConfigurableLanguage entity.
*
* @group language
* @see \Drupal\language\Entity\ConfigurableLanguage.
*/
class ConfigurableLanguageTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('language');
/**
* Tests configurable language name methods.
*/
public function testName() {
$name = $this->randomMachineName();
$language_code = $this->randomMachineName(2);
$configurableLanguage = new ConfigurableLanguage(array('label' => $name, 'id' => $language_code), 'configurable_language');
$this->assertEqual($configurableLanguage->getName(), $name);
$this->assertEqual($configurableLanguage->setName('Test language')->getName(), 'Test language');
}
}
......@@ -38,13 +38,14 @@ public function testDirection() {
/**
* @covers ::getWeight
* @covers ::setWeight
*/
public function testWeight() {
// The weight, an integer. Used to order languages with larger positive
// weights sinking items toward the bottom of lists.
$weight = -5;
$configurableLanguage = new ConfigurableLanguage(array('weight' => $weight), 'configurable_language');
$this->assertEquals($configurableLanguage->getWeight(), $weight);
$configurableLanguage = new ConfigurableLanguage(array('weight' => -5), 'configurable_language');
$this->assertEquals($configurableLanguage->getWeight(), -5);
$this->assertEquals($configurableLanguage->setWeight(13)->getWeight(), 13);
}
}
......@@ -33,15 +33,12 @@ public function testConstruct() {
/**
* @covers ::getName
* @covers ::setName
*/
public function testGetName() {
$name = $this->randomMachineName();
$language_code = $this->randomMachineName(2);
$language = new Language(array('id' => $language_code, 'name' => $name));
$this->assertSame($name, $language->getName());
$new_name = $this->randomMachineName();
$this->assertSame($new_name, $language->setName($new_name)->getName());
}
/**
......
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