Commit d1670a7b authored by webchick's avatar webchick

Issue #2246679 by YesCT, alimac, Michelle, martin107, eugenesia: Make Language...

Issue #2246679 by YesCT, alimac, Michelle, martin107, eugenesia: Make Language module's LanguageInterface (to be ConfigurableLanguageInterface) extend Core's LanguageInterface.
parent 0025ee45
......@@ -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 {
}
......@@ -108,10 +108,21 @@ 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;
}
}
<?php
/**
* @file
* Contains \Drupal\language\Tests\ConfigurableLanguageUnitTest.
*/
namespace Drupal\language\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\UnitTestCase;
/**
* Tests the ConfigurableLanguage entity class.
*
* @group language
* @coversDefaultClass \Drupal\language\Entity\ConfigurableLanguage
* @see \Drupal\language\Entity\ConfigurableLanguage.
*/
class ConfigurableLanguageUnitTest extends UnitTestCase {
/**
* The Entity under test.
*
* @var \Drupal\language\Entity\ConfigurableLanguage;
*/
protected $configurableLanguage;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->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.');
}
}
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