diff --git a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
index 331652b..a11ca07 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationFormBase.php
@@ -243,12 +243,12 @@ public function submitForm(array &$form, array &$form_state) {
* The configuration name.
* @param \Drupal\Core\Config\Schema\ArrayElement $schema
* Schema definition of configuration.
- * @param array|string $config_data
- * Configuration object of requested language, a string when done traversing
- * the data building each sub-structure for the form.
- * @param array|string $base_config_data
+ * @param array|string $source_config
* Configuration object of base language, a string when done traversing
* the data building each sub-structure for the form.
+ * @param array|string $translation_config
+ * Configuration object of requested language, a string when done traversing
+ * the data building each sub-structure for the form.
* @param bool $open
* (optional) Whether or not the details element of the form should be open.
* Defaults to TRUE.
@@ -261,7 +261,7 @@ public function submitForm(array &$form, array &$form_state) {
* @return array
* An associative array containing the structure of the form.
*/
- protected function buildConfigForm($name, ArrayElement $schema, $config_data, $base_config_data, $open = TRUE, $base_key = NULL) {
+ protected function buildConfigForm($name, ArrayElement $schema, $source_config, $translation_config, $open = TRUE, $base_key = NULL) {
$build = array();
foreach ($schema as $key => $element) {
// Make the specific element key, "$base_key.$key".
@@ -285,13 +285,13 @@ protected function buildConfigForm($name, ArrayElement $schema, $config_data, $b
// configuration values contained in the element.
if (!empty($definition['translatable'])) {
/** @var \Drupal\config_translation\FormElement\ElementInterface $form_element */
- $form_element = new $definition['form_element_class']();
+ $form_element = new $definition['form_element_class']($definition);
$build[$element_key] = array(
'#theme' => 'config_translation_manage_form_element',
);
- $build[$element_key]['source'] = $form_element->getSourceElement($definition, $this->sourceLanguage, $base_config_data[$key]);
- $build[$element_key]['translation'] = $form_element->getTranslationElement($definition, $this->language, $base_config_data[$key], $config_data[$key]);
+ $build[$element_key]['source'] = $form_element->getSourceElement($this->sourceLanguage, $source_config[$key]);
+ $build[$element_key]['translation'] = $form_element->getTranslationElement($this->language, $source_config[$key], $translation_config[$key]);
// For accessibility we make source and translation appear next to each
// other in the source for each element, which is why we utilize the
// 'source' and 'translation' sub-keys for the form. The form values,
@@ -310,7 +310,7 @@ protected function buildConfigForm($name, ArrayElement $schema, $config_data, $b
elseif ($element instanceof ArrayElement) {
// Build sub-structure and include it with a wrapper in the form
// if there are any translatable elements there.
- $sub_build = $this->buildConfigForm($name, $element, $config_data[$key], $base_config_data[$key], FALSE, $element_key);
+ $sub_build = $this->buildConfigForm($name, $element, $source_config[$key], $translation_config[$key], FALSE, $element_key);
if (!empty($sub_build)) {
// For some configuration elements the same element structure can
// repeat multiple times, (like views displays, filters, etc.).
diff --git a/core/modules/config_translation/src/FormElement/DateFormat.php b/core/modules/config_translation/src/FormElement/DateFormat.php
index 952ce4f..7ba7203 100644
--- a/core/modules/config_translation/src/FormElement/DateFormat.php
+++ b/core/modules/config_translation/src/FormElement/DateFormat.php
@@ -11,7 +11,6 @@
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Language\LanguageInterface;
-use Drupal\Core\TypedData\DataDefinitionInterface;
/**
* Defines the date format element for the configuration translation interface.
@@ -21,7 +20,7 @@ class DateFormat extends FormElementBase {
/**
* {@inheritdoc}
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $translation_language, $source_config, $translation_config) {
+ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
$description = $this->t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/function.date.php'));
$format = $this->t('Displayed as %date_format', array('%date_format' => \Drupal::service('date')->format(REQUEST_TIME, 'custom', $translation_config)));
@@ -34,7 +33,7 @@ public function getTranslationElement(DataDefinitionInterface $definition, Langu
'event' => 'keyup',
'progress' => array('type' => 'throbber', 'message' => NULL),
),
- ) + parent::getTranslationElement($definition, $translation_language, $source_config, $translation_config);
+ ) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
/**
diff --git a/core/modules/config_translation/src/FormElement/ElementInterface.php b/core/modules/config_translation/src/FormElement/ElementInterface.php
index cb2c728..2448daa 100644
--- a/core/modules/config_translation/src/FormElement/ElementInterface.php
+++ b/core/modules/config_translation/src/FormElement/ElementInterface.php
@@ -23,8 +23,6 @@
* what is considered to provide a more intuitive user interface for the
* translator.
*
- * @param \Drupal\Core\TypedData\DataDefinitionInterface $definition
- * The configuration schema for the element.
* @param \Drupal\Core\Language\LanguageInterface $source_language
* Thee source language of the configuration object.
* @param mixed $source_config
@@ -33,7 +31,7 @@
* @return array
* A render array for the source value.
*/
- public function getSourceElement(DataDefinitionInterface $definition, LanguageInterface $source_language, $source_config);
+ public function getSourceElement(LanguageInterface $source_language, $source_config);
/**
* Returns the translation form element for a given configuration definition.
@@ -73,8 +71,6 @@ public function getSourceElement(DataDefinitionInterface $definition, LanguageIn
* translation of complex data, similar access logic must be implemented
* manually.
*
- * @param \Drupal\Core\TypedData\DataDefinitionInterface $definition
- * The configuration schema for the element.
* @param \Drupal\Core\Language\LanguageInterface $language
* The language to display the translation form for.
* @param mixed $source_config
@@ -88,6 +84,6 @@ public function getSourceElement(DataDefinitionInterface $definition, LanguageIn
* @see \Drupal\config_translation\FormElement\TextFormat
* @see filter_process_format()
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $language, $source_config, $translation_config);
+ public function getTranslationElement(LanguageInterface $language, $source_config, $translation_config);
}
diff --git a/core/modules/config_translation/src/FormElement/FormElementBase.php b/core/modules/config_translation/src/FormElement/FormElementBase.php
index 89e7b04..5a1bab0 100644
--- a/core/modules/config_translation/src/FormElement/FormElementBase.php
+++ b/core/modules/config_translation/src/FormElement/FormElementBase.php
@@ -19,9 +19,25 @@
use StringTranslationTrait;
/**
+ * The data definition of the element this form element is for.
+ *
+ * @var \Drupal\Core\TypedData\DataDefinitionInterface
+ */
+ protected $definition;
+
+ /**
+ * Constructs a FormElementBase.
+ *
+ * @param \Drupal\Core\TypedData\DataDefinitionInterface $definition
+ */
+ public function __construct(DataDefinitionInterface $definition) {
+ $this->definition = $definition;
+ }
+
+ /**
* {@inheritdoc}
*/
- public function getSourceElement(DataDefinitionInterface $definition, LanguageInterface $source_language, $source_config) {
+ public function getSourceElement(LanguageInterface $source_language, $source_config) {
if ($source_config) {
$value = '' . nl2br($source_config) . '';
}
@@ -32,7 +48,7 @@ public function getSourceElement(DataDefinitionInterface $definition, LanguageIn
return array(
'#type' => 'item',
'#title' => $this->t('!label (!source_language)', array(
- '!label' => $this->t($definition->getLabel()),
+ '!label' => $this->t($this->definition->getLabel()),
'!source_language' => $source_language->getName(),
)),
'#markup' => $value,
@@ -43,11 +59,11 @@ public function getSourceElement(DataDefinitionInterface $definition, LanguageIn
/**
* {@inheritdoc}
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $translation_language, $source_config, $translation_config) {
+ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
// Add basic properties that apply to all form elements.
return array(
'#title' => $this->t('!label (!source_language)', array(
- '!label' => $this->t($definition['label']),
+ '!label' => $this->t($this->definition['label']),
'!source_language' => $translation_language->getName(),
)),
'#default_value' => $translation_config,
diff --git a/core/modules/config_translation/src/FormElement/TextFormat.php b/core/modules/config_translation/src/FormElement/TextFormat.php
index c1b03ca..1f8f3e7 100644
--- a/core/modules/config_translation/src/FormElement/TextFormat.php
+++ b/core/modules/config_translation/src/FormElement/TextFormat.php
@@ -8,7 +8,6 @@
namespace Drupal\config_translation\FormElement;
use Drupal\Core\Language\LanguageInterface;
-use Drupal\Core\TypedData\DataDefinitionInterface;
/**
* Defines the text_format element for the configuration translation interface.
@@ -18,11 +17,11 @@ class TextFormat extends FormElementBase {
/**
* {@inheritdoc}
*/
- public function getSourceElement(DataDefinitionInterface $definition, LanguageInterface $source_language, $source_config) {
+ public function getSourceElement(LanguageInterface $source_language, $source_config) {
// Instead of the formatted output show a disabled textarea. This allows for
// easier side-by-side comparison, especially with formats with text
// editors.
- return $this->getTranslationElement($definition, $source_language, $source_config, $source_config) + array(
+ return $this->getTranslationElement($source_language, $source_config, $source_config) + array(
'#value' => $source_config['value'],
'#disabled' => TRUE,
'#allow_focus' => TRUE,
@@ -32,14 +31,14 @@ public function getSourceElement(DataDefinitionInterface $definition, LanguageIn
/**
* {@inheritdoc}
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $translation_language, $source_config, $translation_config) {
+ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
return array(
'#type' => 'text_format',
// Override the #default_value property from the parent class.
'#default_value' => $translation_config['value'],
'#format' => $translation_config['format'],
'#allowed_formats' => array($source_config['format']),
- ) + parent::getTranslationElement($definition, $translation_language, $source_config, $translation_config);
+ ) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
diff --git a/core/modules/config_translation/src/FormElement/Textarea.php b/core/modules/config_translation/src/FormElement/Textarea.php
index 2dfe9aa..17ee1a2 100644
--- a/core/modules/config_translation/src/FormElement/Textarea.php
+++ b/core/modules/config_translation/src/FormElement/Textarea.php
@@ -8,7 +8,6 @@
namespace Drupal\config_translation\FormElement;
use Drupal\Core\Language\LanguageInterface;
-use Drupal\Core\TypedData\DataDefinitionInterface;
/**
* Defines the textarea element for the configuration translation interface.
@@ -18,7 +17,7 @@ class Textarea extends FormElementBase {
/**
* {@inheritdoc}
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $translation_language, $source_config, $translation_config) {
+ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
// Estimate a comfortable size of the input textarea.
$rows_words = ceil(str_word_count($translation_config) / 5);
$rows_newlines = substr_count($translation_config, "\n" ) + 1;
@@ -27,7 +26,7 @@ public function getTranslationElement(DataDefinitionInterface $definition, Langu
return array(
'#type' => 'textarea',
'#rows' => $rows,
- ) + parent::getTranslationElement($definition, $translation_language, $source_config, $translation_config);
+ ) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
}
diff --git a/core/modules/config_translation/src/FormElement/Textfield.php b/core/modules/config_translation/src/FormElement/Textfield.php
index 3ebd72b..87632f4 100644
--- a/core/modules/config_translation/src/FormElement/Textfield.php
+++ b/core/modules/config_translation/src/FormElement/Textfield.php
@@ -8,7 +8,6 @@
namespace Drupal\config_translation\FormElement;
use Drupal\Core\Language\LanguageInterface;
-use Drupal\Core\TypedData\DataDefinitionInterface;
/**
* Defines the textfield element for the configuration translation interface.
@@ -18,10 +17,10 @@ class Textfield extends FormElementBase {
/**
* {@inheritdoc}
*/
- public function getTranslationElement(DataDefinitionInterface $definition, LanguageInterface $translation_language, $source_config, $translation_config) {
+ public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
return array(
'#type' => 'textfield',
- ) + parent::getTranslationElement($definition, $translation_language, $source_config, $translation_config);
+ ) + parent::getTranslationElement($translation_language, $source_config, $translation_config);
}
}
diff --git a/core/modules/locale/src/LocaleConfigSubscriber.php b/core/modules/locale/src/LocaleConfigSubscriber.php
index 651651b..fdf4bff 100644
--- a/core/modules/locale/src/LocaleConfigSubscriber.php
+++ b/core/modules/locale/src/LocaleConfigSubscriber.php
@@ -16,6 +16,14 @@
/**
* Updates corresponding string translation when language overrides change.
+ *
+ * This reacts to the updating or deleting of configuration language overrides.
+ * It checks whether there are string translations associated with the
+ * configuration that is being saved and, if so, updates those string
+ * translations with the new configuration values and marks them as customized.
+ * That way manual updates to configuration will not be inadvertently reverted
+ * when updated translations from https://localize.drupal.org are being
+ * imported.
*/
class LocaleConfigSubscriber implements EventSubscriberInterface {