summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2013-10-13 12:03:10 (GMT)
committerNathaniel Catchpole2013-10-13 12:03:10 (GMT)
commitcc36f2cabc4bc6a38fe5b7f1989f4f3a63e09cb9 (patch)
tree3a93453b1b1cefbc1b63322bd0f6ba1e83fbeb92
parent54593549824997423016b7b05a9b58f57148bd78 (diff)
Issue #2099541 by stefan.r, Schnitzel, Gábor Hojtsy: Fixed ConfigEntities should not load the Entity translated on Edit Forms.
-rw-r--r--core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php65
-rw-r--r--core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php6
-rw-r--r--core/modules/locale/locale.services.yml5
3 files changed, 75 insertions, 1 deletions
diff --git a/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php b/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php
new file mode 100644
index 0000000..5061be2
--- /dev/null
+++ b/core/modules/locale/lib/Drupal/locale/ParamConverter/LocaleAdminPathConfigEntityConverter.php
@@ -0,0 +1,65 @@
+<?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;
+ }
+
+}
diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php
index 752f911..7299826 100644
--- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php
+++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleConfigTranslationTest.php
@@ -43,7 +43,7 @@ class LocaleConfigTranslationTest extends WebTestBase {
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 @@ class LocaleConfigTranslationTest extends WebTestBase {
// 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.');
}
}
diff --git a/core/modules/locale/locale.services.yml b/core/modules/locale/locale.services.yml
index 776cb3b..f831989 100644
--- a/core/modules/locale/locale.services.yml
+++ b/core/modules/locale/locale.services.yml
@@ -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']