diff --git a/core/modules/language/src/ConfigurableLanguageInterface.php b/core/modules/language/src/ConfigurableLanguageInterface.php index 03cd14d..16536a1 100644 --- a/core/modules/language/src/ConfigurableLanguageInterface.php +++ b/core/modules/language/src/ConfigurableLanguageInterface.php @@ -8,10 +8,11 @@ namespace Drupal\language; use Drupal\Core\Config\Entity\ConfigEntityInterface; +use Drupal\Core\Language\LanguageInterface; /** * Provides an interface defining a language entity. */ -interface ConfigurableLanguageInterface extends ConfigEntityInterface { +interface ConfigurableLanguageInterface extends ConfigEntityInterface, LanguageInterface { } diff --git a/core/modules/language/src/Entity/ConfigurableLanguage.php b/core/modules/language/src/Entity/ConfigurableLanguage.php index c252010..eda4d9a 100644 --- a/core/modules/language/src/Entity/ConfigurableLanguage.php +++ b/core/modules/language/src/Entity/ConfigurableLanguage.php @@ -109,9 +109,20 @@ class ConfigurableLanguage extends ConfigEntityBase implements ConfigurableLangu protected $preSaveMultilingual; /** + * The language negotiation method used when a language was detected. + * + * The method ID, for example + * \Drupal\language\LanguageNegotiatorInterface::METHOD_ID. + * + * @var string + */ + public $methodId; + + /** * Sets the default flag on the language entity. * * @param bool $default + * TRUE if the language entity is the site default language, FALSE if not. */ public function setDefault($default) { $this->default = $default; @@ -201,7 +212,9 @@ protected function toLanguageObject() { /** * {@inheritdoc} * - * @throws \RuntimeException + * @throws \DeleteDefaultLanguageException + * Exception thrown if we're trying to delete the default language entity. + * This is not allowed as a site must have a default language. */ public static function preDelete(EntityStorageInterface $storage, array $entities) { $default_langcode = static::getDefaultLangcode(); @@ -235,4 +248,75 @@ protected static function getDefaultLangcode() { return $language->getId(); } + /** + * {@inheritdoc} + */ + public function getName() { + return $this->label(); + } + + /** + * {@inheritdoc} + */ + public function setName($name) { + $this->label = $name; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getId() { + return $this->id(); + } + + /** + * {@inheritdoc} + */ + public function getDirection() { + return $this->direction; + } + + /** + * {@inheritdoc} + */ + public function setDirection($direction) { + $this->direction = $direction; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getWeight() { + return $this->weight; + } + + /** + * {@inheritdoc} + */ + public function setWeight($weight) { + $this->weight = $weight; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getNegotiationMethodId() { + return $this->methodId; + } + + /** + * {@inheritdoc} + */ + public function setNegotiationMethodId($method_id) { + $this->methodId = $method_id; + + return $this; + } + } diff --git a/core/modules/language/src/Tests/ConfigurableLanguageUnitTest.php b/core/modules/language/src/Tests/ConfigurableLanguageUnitTest.php new file mode 100644 index 0000000..7f193d4 --- /dev/null +++ b/core/modules/language/src/Tests/ConfigurableLanguageUnitTest.php @@ -0,0 +1,80 @@ +configurableLanguage = new ConfigurableLanguage(array(), 'configurable_language'); + } + + /** + * @covers ::setDirection + * @covers ::getDirection + */ + public function testDirection() { + // Direction of language writing, an integer. Usually either + // ConfigurableLanguage::DIRECTION_LTR or + // ConfigurableLanguage::DIRECTION_RTL. + $set_direction_ltr = ConfigurableLanguage::DIRECTION_LTR; + $this->configurableLanguage->setDirection($set_direction_ltr); + $this->assertEquals($this->configurableLanguage->getDirection(), $set_direction_ltr, 'LTR direction written and read correctly.'); + + // Test direction again, setting direction to RTL. + $set_direction_rtl = ConfigurableLanguage::DIRECTION_RTL; + $this->configurableLanguage->setDirection($set_direction_rtl); + $this->assertEquals($this->configurableLanguage->getDirection(), $set_direction_rtl, 'RTL direction written and read correctly.'); + } + + /** + * @covers ::setWeight + * @covers ::getWeight + */ + public function testWeight() { + // The weight, an integer. Used to order languages with larger positive + // weights sinking items toward the bottom of lists. + $set_weight = -5; + $this->configurableLanguage->setWeight($set_weight); + $this->assertEquals($this->configurableLanguage->getWeight(), $set_weight, 'Weight written and read correctly.'); + } + + /** + * @covers::setNegotiationMethodId + * @covers::setNegotiationMethodId + */ + public function testNegotiationMethodId(){ + // Language's negotiation method ID, a string. E.g. + // \Drupal\language\LanguageNegotiatorInterface::METHOD_ID. + $set_method_id = 'language-foomethod'; + $this->configurableLanguage->setNegotiationMethodId($set_method_id); + $this->assertEquals($this->configurableLanguage->getNegotiationMethodId(), $set_method_id, 'Negotiation Method Identifier written and read correctly.'); + } + +}