Commit cc36f2ca authored by catch's avatar catch

Issue #2099541 by stefan.r, Schnitzel, Gábor Hojtsy: Fixed ConfigEntities...

Issue #2099541 by stefan.r, Schnitzel, Gábor Hojtsy: Fixed ConfigEntities should not load the Entity translated on Edit Forms.
parent 54593549
<?php
/**
* @file
* Contains \Drupal\locale\ParamConverter\LocaleAdminPathConfigEntityConverter.
*/
namespace Drupal\locale\ParamConverter;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Drupal\Core\ParamConverter\EntityConverter;
use Drupal\Core\ParamConverter\ParamConverterInterface;
/**
* Makes sure the untranslated ConfigEntity is loaded on admin pages.
*
* Converts entity route arguments to untranslated entities (in their original
* submission language) as opposed to converting to entities with overrides in
* the negotiated language.
*
* This converter applies only if the path is an admin path.
*
* Due to this converter having a higher weight than the default
* EntityConverter, every time this applies, it takes over the conversion duty
* from EntityConverter. As we only allow a single converter per route
* argument, EntityConverter is ignored when this converter applies.
*/
class LocaleAdminPathConfigEntityConverter extends EntityConverter {
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request) {
$entity_type = substr($definition['type'], strlen('entity:'));
if ($storage = $this->entityManager->getStorageController($entity_type)) {
// Enter the override-free context, so we can ensure no overrides are
// applied.
config_context_enter('config.context.free');
$entity = $storage->load($value);
// Leave the override-free context.
config_context_leave();
return $entity;
}
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
if (parent::applies($definition, $name, $route)) {
// As we only want to override EntityConverter for ConfigEntities, find
// out whether the current entity is a ConfigEntity.
$entity_type = substr($definition['type'], strlen('entity:'));
$info = $this->entityManager->getDefinition($entity_type);
if (is_subclass_of($info['class'], '\Drupal\Core\Config\Entity\ConfigEntityInterface')) {
// path_is_admin() needs the path without the leading slash.
$path = ltrim($route->getPath(), '/');
return path_is_admin($path);
}
}
return FALSE;
}
}
......@@ -43,7 +43,7 @@ public function setUp() {
function testConfigTranslation() {
// Add custom language.
$langcode = 'xx';
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface', 'administer modules', 'access site-wide contact form'));
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface', 'administer modules', 'access site-wide contact form', 'administer contact forms'));
$this->drupalLogin($admin_user);
$name = $this->randomName(16);
$edit = array(
......@@ -164,6 +164,10 @@ function testConfigTranslation() {
// upcasting will already work.
$this->drupalGet($langcode . '/contact/feedback');
$this->assertText($category_label);
// Check if the UI does not show the translated String.
$this->drupalGet('admin/structure/contact/manage/feedback');
$this->assertFieldById('edit-label', 'Website feedback', 'Translation is not loaded for Edit Form.');
}
}
......@@ -4,6 +4,11 @@ services:
tags:
- { name: event_subscriber }
arguments: ['@language_manager', '@config.context']
paramconverter.configentity_admin:
class: Drupal\locale\ParamConverter\LocaleAdminPathConfigEntityConverter
tags:
- { name: paramconverter, priority: 5 }
arguments: ['@entity.manager']
locale.config.typed:
class: Drupal\locale\LocaleConfigManager
arguments: ['@config.storage', '@config.storage.schema', '@config.storage.installer', '@locale.storage']
......
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