Commit 6109cb9c authored by catch's avatar catch

Issue #2602268 by Berdir: Translated string are loaded into Views UI and then...

Issue #2602268 by Berdir: Translated string are loaded into Views UI and then saved as default language strings
parent d809e478
......@@ -7,8 +7,10 @@
namespace Drupal\views_ui\ParamConverter;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Core\ParamConverter\AdminPathConfigEntityConverter;
use Drupal\Core\Routing\AdminContext;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\ParamConverterInterface;
use Drupal\user\SharedTempStoreFactory;
......@@ -30,7 +32,7 @@
* Views UI and loaded from the views temp store, but it will not touch the
* value for {bar}.
*/
class ViewUIConverter extends EntityConverter implements ParamConverterInterface {
class ViewUIConverter extends AdminPathConfigEntityConverter implements ParamConverterInterface {
/**
* Stores the tempstore factory.
......@@ -47,8 +49,18 @@ class ViewUIConverter extends EntityConverter implements ParamConverterInterface
* @param \Drupal\user\SharedTempStoreFactory $temp_store_factory
* The factory for the temp store object.
*/
public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory) {
parent::__construct($entity_manager);
public function __construct(EntityManagerInterface $entity_manager, SharedTempStoreFactory $temp_store_factory, ConfigFactoryInterface $config_factory = NULL, AdminContext $admin_context = NULL) {
// The config factory and admin context are new arguments due to changing
// the parent. Avoid an error on updated sites by falling back to getting
// them from the container.
// @todo Remove in 8.2.x in https://www.drupal.org/node/2674328.
if (!$config_factory) {
$config_factory = \Drupal::configFactory();
}
if (!$admin_context) {
$admin_context = \Drupal::service('router.admin_context');
}
parent::__construct($entity_manager, $config_factory, $admin_context);
$this->tempStoreFactory = $temp_store_factory;
}
......
<?php
/**
* @file
* Contains \Drupal\views_ui\Tests\TranslatedStringTest.
*/
namespace Drupal\views_ui\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
/**
* Tests that translated strings in views UI don't override original strings.
*
* @group views_ui
*/
class TranslatedViewTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'config_translation',
'views_ui',
];
/**
* Languages to enable.
*
* @var array
*/
protected $langcodes = [
'fr',
];
/**
* Administrator user for tests.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected function setUp() {
parent::setUp();
$permissions = [
'administer site configuration',
'administer views',
'translate configuration',
'translate interface',
];
// Create and login user.
$this->adminUser = $this->drupalCreateUser($permissions);
$this->drupalLogin($this->adminUser);
// Add languages.
foreach ($this->langcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
$this->resetAll();
$this->rebuildContainer();
}
public function testTranslatedStrings() {
$translation_url = 'admin/structure/views/view/files/translate/fr/add';
$edit_url = 'admin/structure/views/view/files';
// Check origial string.
$this->drupalGet($edit_url);
$this->assertTitle('Files (File) | Drupal');
// Translate the label of the view.
$this->drupalGet($translation_url);
$edit = [
'translation[config_names][views.view.files][label]' => 'Fichiers',
];
$this->drupalPostForm(NULL, $edit, t('Save translation'));
// Check if the label is translated.
$this->drupalGet($edit_url, ['language' => \Drupal::languageManager()->getLanguage('fr')]);
$this->assertTitle('Files (File) | Drupal');
$this->assertNoText('Fichiers');
}
}
services:
paramconverter.views_ui:
class: Drupal\views_ui\ParamConverter\ViewUIConverter
arguments: ['@entity.manager', '@user.shared_tempstore']
arguments: ['@entity.manager', '@user.shared_tempstore', '@config.factory', '@router.admin_context']
tags:
- { name: paramconverter, priority: 10 }
lazy: true
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