Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPENEUROPA-2768: Remove presave that forces language configuration. #99

Merged
merged 2 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions oe_multilingual.module
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ declare(strict_types = 1);
use Drupal\Component\Gettext\PoStreamReader;
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\TypedData\TranslatableInterface;
Expand Down Expand Up @@ -70,22 +69,6 @@ function oe_multilingual_preprocess_language_selection_page_content(&$variables)
}
}

/**
* Implements hook_ENTITY_TYPE_presave() for the configurable language entities.
*
* Make sure whenever we add or re-add a language it follows the configuration
* set by the module's configuration files.
*/
function oe_multilingual_configurable_language_presave(EntityInterface $entity) {
$storage = new FileStorage(drupal_get_path('module', 'oe_multilingual') . '/config/install');
$values = $storage->read('language.entity.' . $entity->id());
if ($values) {
foreach ($values as $key => $value) {
$entity->set($key, $value);
}
}
}

/**
* Implements hook_ENTITY_TYPE_insert() for the configurable language entities.
*
Expand Down
30 changes: 0 additions & 30 deletions tests/Kernel/InstallationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,6 @@ protected function setUp() {
oe_multilingual_install();
}

/**
* Test languages keep the configuration after being deleted and recreated.
*/
public function testLanguageConfiguration(): void {
// Delete a language.
$storage = $this->container->get('entity_type.manager')->getStorage('configurable_language');
/** @var \Drupal\language\Entity\ConfigurableLanguage $old_language */
$old_language = $storage->load('fr');
$old_language->delete();

// Assert the language is deleted.
$language = $storage->load('fr');
$this->assertNull($language);

// Create the same language.
/** @var \Drupal\language\ConfigurableLanguageInterface $new_language */
$new_language = $storage->create(['id' => 'fr']);
$new_language->save();
$new_language = $storage->load('fr');

// Assert the same values apply.
$this->assertEquals($old_language->id(), $new_language->id());
$this->assertEquals($old_language->getWeight(), $new_language->getWeight());
$this->assertEquals($old_language->getName(), $new_language->getName());

// Ensure the correct translation is also present.
$translation = $this->container->get('language_manager')->getLanguageConfigOverride('fr', 'language.entity.fr');
$this->assertEquals('français', $translation->get('label'));
}

/**
* Test proper configuration setup during module installation.
*/
Expand Down