Commit 21a11cf5 authored by catch's avatar catch

Issue #2336177 by alexpott, YesCT: Fixed ConfigurableLanguage cannot be...

Issue #2336177 by alexpott, YesCT: Fixed ConfigurableLanguage cannot be created/removed directly, integrate language_save() and language_delete().
parent 2ef89a6a
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
use Drupal\Core\StringTranslation\Translator\FileTranslation; use Drupal\Core\StringTranslation\Translator\FileTranslation;
use Drupal\Core\Extension\ExtensionDiscovery; use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\language\Entity\ConfigurableLanguage;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
...@@ -1548,30 +1549,14 @@ function install_import_translations(&$install_state) { ...@@ -1548,30 +1549,14 @@ function install_import_translations(&$install_state) {
include_once __DIR__ . '/../modules/locale/locale.bulk.inc'; include_once __DIR__ . '/../modules/locale/locale.bulk.inc';
$langcode = $install_state['parameters']['langcode']; $langcode = $install_state['parameters']['langcode'];
$standard_languages = LanguageManager::getStandardLanguageList(); $language = ConfigurableLanguage::createFromLangcode($langcode);
if (!isset($standard_languages[$langcode])) { $language->set('default', TRUE);
// Drupal does not know about this language, so we prefill its values with $language->save();
// our best guess. The user will be able to edit afterwards.
$language = new Language(array(
'id' => $langcode,
'name' => $langcode,
'default' => TRUE,
));
language_save($language);
}
else {
// A known predefined language, details will be filled in properly.
$language = new Language(array(
'id' => $langcode,
'default' => TRUE,
));
language_save($language);
}
// If a non-English language was selected, remove English and import the // If a non-English language was selected, remove English and import the
// translations. // translations.
if ($langcode != 'en') { if ($langcode != 'en') {
language_delete('en'); entity_delete_multiple('configurable_language', array('en'));
// Set up a batch to import translations for the newly added language. // Set up a batch to import translations for the newly added language.
_install_prepare_import($langcode); _install_prepare_import($langcode);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\aggregator\Tests; namespace Drupal\aggregator\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
/** /**
* Tests aggregator feeds in multiple languages. * Tests aggregator feeds in multiple languages.
...@@ -34,13 +34,13 @@ protected function setUp() { ...@@ -34,13 +34,13 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Create test languages. // Create test languages.
$this->langcodes = array(language_load('en')); $this->langcodes = array(ConfigurableLanguage::load('en'));
for ($i = 1; $i < 3; ++$i) { for ($i = 1; $i < 3; ++$i) {
$language = new Language(array( $language = ConfigurableLanguage::create(array(
'id' => 'l' . $i, 'id' => 'l' . $i,
'name' => $this->randomString(), 'label' => $this->randomString(),
)); ));
language_save($language); $language->save();
$this->langcodes[$i] = $language; $this->langcodes[$i] = $language;
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\basic_auth\Tests\Authentication; namespace Drupal\basic_auth\Tests\Authentication;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -119,8 +119,7 @@ function testPerUserLoginFloodControl() { ...@@ -119,8 +119,7 @@ function testPerUserLoginFloodControl() {
* Tests compatibility with locale/UI translation. * Tests compatibility with locale/UI translation.
*/ */
function testLocale() { function testLocale() {
$language = new Language(array('id' => 'de', 'default' => TRUE)); ConfigurableLanguage::create(array('id' => 'de', 'label' => 'German', 'default' => TRUE))->save();
language_save($language);
$account = $this->drupalCreateUser(); $account = $this->drupalCreateUser();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\block\Tests; namespace Drupal\block\Tests;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -36,13 +36,13 @@ protected function setUp() { ...@@ -36,13 +36,13 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Create test languages. // Create test languages.
$this->langcodes = array(language_load('en')); $this->langcodes = array(ConfigurableLanguage::load('en'));
for ($i = 1; $i < 3; ++$i) { for ($i = 1; $i < 3; ++$i) {
$language = new Language(array( $language = ConfigurableLanguage::create(array(
'id' => 'l' . $i, 'id' => 'l' . $i,
'name' => $this->randomString(), 'label' => $this->randomString(),
)); ));
language_save($language); $language->save();
$this->langcodes[$i] = $language; $this->langcodes[$i] = $language;
} }
} }
......
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
namespace Drupal\comment\Tests\Views; namespace Drupal\comment\Tests\Views;
use Drupal\Core\Language\Language;
use Drupal\field\Entity\FieldStorageConfig; use Drupal\field\Entity\FieldStorageConfig;
use Drupal\language\Entity\ConfigurableLanguage;
/** /**
* Tests comment field filters with translations. * Tests comment field filters with translations.
...@@ -40,17 +40,8 @@ function setUp() { ...@@ -40,17 +40,8 @@ function setUp() {
parent::setUp(); parent::setUp();
// Add two new languages. // Add two new languages.
$language = new Language(array( ConfigurableLanguage::createFromLangcode('fr')->save();
'id' => 'fr', ConfigurableLanguage::createFromLangcode('es')->save();
'name' => 'French',
));
language_save($language);
$language = new Language(array(
'id' => 'es',
'name' => 'Spanish',
));
language_save($language);
// Make the comment body field translatable. The title is already // Make the comment body field translatable. The title is already
// translatable by definition. // translatable by definition.
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\config\Tests; namespace Drupal\config\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\DrupalUnitTestBase; use Drupal\simpletest\DrupalUnitTestBase;
/** /**
...@@ -44,14 +44,8 @@ function testConfigLanguageOverride() { ...@@ -44,14 +44,8 @@ function testConfigLanguageOverride() {
$raw = $config->getRawData(); $raw = $config->getRawData();
$this->assertIdentical($raw['foo'], 'bar'); $this->assertIdentical($raw['foo'], 'bar');
language_save(new Language(array( ConfigurableLanguage::createFromLangcode('fr')->save();
'name' => 'French', ConfigurableLanguage::createFromLangcode('de')->save();
'id' => 'fr',
)));
language_save(new Language(array(
'name' => 'German',
'id' => 'de',
)));
\Drupal::languageManager()->setConfigOverrideLanguage(language_load('fr')); \Drupal::languageManager()->setConfigOverrideLanguage(language_load('fr'));
$config = \Drupal::config('config_test.system'); $config = \Drupal::config('config_test.system');
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\config\Tests; namespace Drupal\config\Tests;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -36,7 +37,7 @@ function testSiteNameTranslation() { ...@@ -36,7 +37,7 @@ function testSiteNameTranslation() {
$edit = array( $edit = array(
'predefined_langcode' => 'custom', 'predefined_langcode' => 'custom',
'langcode' => $langcode, 'langcode' => $langcode,
'name' => $name, 'label' => $name,
'direction' => LanguageInterface::DIRECTION_LTR, 'direction' => LanguageInterface::DIRECTION_LTR,
); );
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
...@@ -66,10 +67,11 @@ function testSiteNameTranslation() { ...@@ -66,10 +67,11 @@ function testSiteNameTranslation() {
// overrides still work. // overrides still work.
$language_manager = \Drupal::languageManager()->reset(); $language_manager = \Drupal::languageManager()->reset();
$this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.'); $this->assertTrue($language_manager->isMultilingual(), 'The test site is multilingual.');
$language = \Drupal::languageManager()->getLanguage('xx'); $language = ConfigurableLanguage::load('xx');
$language->default = TRUE; $language->set('default', TRUE);
language_save($language); $language->save();
language_delete('en');
ConfigurableLanguage::load('en')->delete();
$this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.'); $this->assertFalse($language_manager->isMultilingual(), 'The test site is monolingual.');
$this->drupalGet('xx'); $this->drupalGet('xx');
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\config_translation\Tests; namespace Drupal\config_translation\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -45,8 +45,7 @@ protected function setUp() { ...@@ -45,8 +45,7 @@ protected function setUp() {
$this->pluginId = key($definitions); $this->pluginId = key($definitions);
$this->langcode = 'xx'; $this->langcode = 'xx';
$language = new Language(array('id' => $this->langcode, 'name' => 'XX')); ConfigurableLanguage::create(array('id' => $this->langcode, 'label' => 'XX'))->save();
language_save($language);
\Drupal::state()->set('config_translation_test_alter_form_alter', TRUE); \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\config_translation\Tests; namespace Drupal\config_translation\Tests;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -325,8 +325,7 @@ public function doUserRoleListTest() { ...@@ -325,8 +325,7 @@ public function doUserRoleListTest() {
public function doLanguageListTest() { public function doLanguageListTest() {
// Create a test language to decouple looking for translate operations // Create a test language to decouple looking for translate operations
// link so this does not test more than necessary. // link so this does not test more than necessary.
$language = new Language(array('id' => 'ga', 'name' => 'Irish')); ConfigurableLanguage::createFromLangcode('ga')->save();
language_save($language);
// Get the language listing. // Get the language listing.
$this->drupalGet('admin/config/regional/language'); $this->drupalGet('admin/config/regional/language');
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\config_translation\Tests; namespace Drupal\config_translation\Tests;
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -55,8 +55,7 @@ protected function setUp() { ...@@ -55,8 +55,7 @@ protected function setUp() {
// Add languages. // Add languages.
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$language = new Language(array('id' => $langcode)); ConfigurableLanguage::createFromLangcode($langcode)->save();
language_save($language);
} }
$this->localeStorage = $this->container->get('locale.storage'); $this->localeStorage = $this->container->get('locale.storage');
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\FileStorage;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -78,8 +79,7 @@ protected function setUp() { ...@@ -78,8 +79,7 @@ protected function setUp() {
// Add languages. // Add languages.
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$language = new Language(array('id' => $langcode)); ConfigurableLanguage::createFromLangcode($langcode)->save();
language_save($language);
} }
$this->localeStorage = $this->container->get('locale.storage'); $this->localeStorage = $this->container->get('locale.storage');
} }
...@@ -570,7 +570,7 @@ public function testLocaleDBStorage() { ...@@ -570,7 +570,7 @@ public function testLocaleDBStorage() {
$edit = array( $edit = array(
'predefined_langcode' => 'custom', 'predefined_langcode' => 'custom',
'langcode' => $langcode, 'langcode' => $langcode,
'name' => $name, 'label' => $name,
'direction' => Language::DIRECTION_LTR, 'direction' => Language::DIRECTION_LTR,
); );
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\config_translation\Tests; namespace Drupal\config_translation\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -52,8 +52,7 @@ protected function setUp() { ...@@ -52,8 +52,7 @@ protected function setUp() {
// Add languages. // Add languages.
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
$language = new Language(array('id' => $langcode)); ConfigurableLanguage::createFromLangcode($langcode)->save();
language_save($language);
} }
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\content_translation\Tests; namespace Drupal\content_translation\Tests;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType; use Drupal\node\Entity\NodeType;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
...@@ -65,7 +65,7 @@ protected function setUp() { ...@@ -65,7 +65,7 @@ protected function setUp() {
parent::setUp(); parent::setUp();
// Set up an additional language. // Set up an additional language.
$this->langcodes = array(language_default()->id, 'es'); $this->langcodes = array(language_default()->id, 'es');
language_save(new Language(array('id' => 'es'))); ConfigurableLanguage::createFromLangcode('es')->save();
// Create a content type. // Create a content type.
$this->bundle = $this->randomMachineName(); $this->bundle = $this->randomMachineName();
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
namespace Drupal\content_translation\Tests; namespace Drupal\content_translation\Tests;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage; use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
/** /**
...@@ -101,7 +101,7 @@ protected function setUp() { ...@@ -101,7 +101,7 @@ protected function setUp() {
protected function setupLanguages() { protected function setupLanguages() {
$this->langcodes = array('it', 'fr'); $this->langcodes = array('it', 'fr');
foreach ($this->langcodes as $langcode) { foreach ($this->langcodes as $langcode) {
language_save(new Language(array('id' => $langcode))); ConfigurableLanguage::createFromLangcode($langcode)->save();
} }
array_unshift($this->langcodes, \Drupal::languageManager()->getDefaultLanguage()->id); array_unshift($this->langcodes, \Drupal::languageManager()->getDefaultLanguage()->id);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\field\Tests; namespace Drupal\field\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
/** /**
* Tests multilanguage fields logic. * Tests multilanguage fields logic.
...@@ -97,11 +97,10 @@ protected function setUp() { ...@@ -97,11 +97,10 @@ protected function setUp() {
$this->instance->save(); $this->instance->save();
for ($i = 0; $i < 3; ++$i) { for ($i = 0; $i < 3; ++$i) {
$language = new Language(array( ConfigurableLanguage::create(array(
'id' => 'l' . $i, 'id' => 'l' . $i,
'name' => $this->randomString(), 'label' => $this->randomString(),
)); ))->save();
language_save($language);
} }
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
namespace Drupal\field\Tests; namespace Drupal\field\Tests;
use Drupal\Core\Language\Language; use Drupal\language\Entity\ConfigurableLanguage;
/** /**
* Tests multilanguage fields logic that require a full environment. * Tests multilanguage fields logic that require a full environment.
...@@ -78,11 +78,10 @@ protected function setUp() { ...@@ -78,11 +78,10 @@ protected function setUp() {
->save(); ->save();
for ($i = 0; $i < 3; ++$i) { for ($i = 0; $i < 3; ++$i) {
$language = new Language(array( ConfigurableLanguage::create(array(
'id' => 'l' . $i, 'id' => 'l' . $i,
'name' => $this->randomString(), 'label' => $this->randomString(),
)); ))->save();
language_save($language);
} }
} }
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
namespace Drupal\hal\Tests; namespace Drupal\hal\Tests;
use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Cache\MemoryBackend;
use Drupal\Core\Language\Language;
use Drupal\hal\Encoder\JsonEncoder; use Drupal\hal\Encoder\JsonEncoder;
use Drupal\hal\Normalizer\ContentEntityNormalizer; use Drupal\hal\Normalizer\ContentEntityNormalizer;
use Drupal\hal\Normalizer\EntityReferenceItemNormalizer; use Drupal\hal\Normalizer\EntityReferenceItemNormalizer;
use Drupal\hal\Normalizer\FieldItemNormalizer; use Drupal\hal\Normalizer\FieldItemNormalizer;
use Drupal\hal\Normalizer\FieldNormalizer; use Drupal\hal\Normalizer\FieldNormalizer;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\rest\LinkManager\LinkManager; use Drupal\rest\LinkManager\LinkManager;
use Drupal\rest\LinkManager\RelationLinkManager; use Drupal\rest\LinkManager\RelationLinkManager;
use Drupal\rest\LinkManager\TypeLinkManager; use Drupal\rest\LinkManager\TypeLinkManager;
...@@ -66,19 +66,12 @@ protected function setUp() { ...@@ -66,19 +66,12 @@ protected function setUp() {
$this->installEntitySchema('entity_test'); $this->installEntitySchema('entity_test');
$this->installConfig(array('field', 'language')); $this->installConfig(array('field', 'language'));
// Add English as a language.
$english = new Language(array(
'id' => 'en',
'name' => 'English',
));
language_save($english);
// Add German as a language. // Add German as a language.
$german = new Language(array( ConfigurableLanguage::create(array(
'id' => 'de', 'id' => 'de',
'name' => 'Deutsch', 'label' => 'Deutsch',
'weight' => -1, 'weight' => -1,
)); ))->save();
language_save($german);
// Create the test text field. // Create the test text field.
entity_create('field_storage_config', array( entity_create('field_storage_config', array(
......
...@@ -6,11 +6,8 @@ ...@@ -6,11 +6,8 @@
*/ */
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\PhpStorage\PhpStorageFactory;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\language\ConfigurableLanguageManager;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Drupal\language\Entity\ConfigurableLanguage; use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUI;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl; use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
...@@ -409,78 +406,6 @@ function language_get_default_langcode($entity_type, $bundle) { ...@@ -409,78 +406,6 @@ function language_get_default_langcode($entity_type, $bundle) {
return $configuration['langcode']; return $configuration['langcode'];
} }
/**
* API function to add or update a language.
*
* @param $language
* Language object with properties corresponding to the 'language'
* configuration properties.
*/
function language_save($language) {
$configurable_language = entity_load('configurable_language', $language->id);
if (!$configurable_language) {
$configurable_language = entity_create('configurable_language', array(
'id' => $language->id,
));
}
$language->is_new = $configurable_language->isNew();
// Assign language properties to language entity.
$configurable_language->label = isset($language->name) ? $language->name : '';
$configurable_language->direction = isset($language->direction) ? $language->direction : '0';
$configurable_language->locked = !empty($language->locked);
$configurable_language->weight = isset($language->weight) ? $language->weight : 0;
$configurable_language->setDefault(!empty($language->default));
$configurable_language->save();
$t_args = array('%language' => $language->name, '%langcode' => $language->id);
if ($language->is_new) {
// Install any available language configuration overrides for the language.
\Drupal::se