Skip to content

Commit

Permalink
Merge pull request #99 from openeuropa/OPENEUROPA-2768
Browse files Browse the repository at this point in the history
OPENEUROPA-2768: Remove presave that forces language configuration.
  • Loading branch information
upchuk authored Feb 5, 2020
2 parents 70cd48e + 0e6210a commit d291e31
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
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

0 comments on commit d291e31

Please sign in to comment.