diff --git a/config_translation.module b/config_translation.module
index c3b5ec9..8eed2ff 100644
--- a/config_translation.module
+++ b/config_translation.module
@@ -227,3 +227,11 @@ function config_translation_entity_operation_alter(array &$operations, \Drupal\C
);
}
}
+
+/**
+ * Implements hook_config_typed_info_alter().
+ */
+function config_translation_config_typed_info_alter(&$definitions) {
+ $definitions['text']['form_element_class'] = '\Drupal\config_translation\FormElement\Textarea';
+ $definitions['date_format']['form_element_class'] = '\Drupal\config_translation\FormElement\DateFormat';
+}
diff --git a/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php b/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php
index 8744728..86ca161 100644
--- a/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php
+++ b/lib/Drupal/config_translation/Form/ConfigTranslationManageForm.php
@@ -220,18 +220,8 @@ class ConfigTranslationManageForm implements FormInterface {
'#type' => 'item',
);
- // Estimate a comfortable size of the input textarea.
- $rows_words = ceil(str_word_count($value) / 5);
- $rows_newlines = substr_count($value, "\n" ) + 1;
- $rows = max($rows_words, $rows_newlines);
-
- $build[$element_key]['translation'] = array(
- '#type' => $this->getFormElementType($definition['type']),
- '#default_value' => $value,
- '#title' => t($definition['label']) . ' (' . $this->language->name . ')',
- '#rows' => $rows,
- '#attributes' => array('lang' => $this->language->id),
- );
+ $class = isset($definition['form_element_class']) ? $definition['form_element_class'] : '\Drupal\config_translation\FormElement\Textfield';
+ $build[$element_key]['translation'] = $class::getFormElement($definition, $this->language, $value);
}
}
return $build;
@@ -305,25 +295,4 @@ class ConfigTranslationManageForm implements FormInterface {
}
}
- /**
- * Provides a mapping of the TypedData element type to form element type.
- *
- * @param string $element_type
- * The element type from the definition of a TypedData object.
- *
- * @return string
- * The form element type.
- */
- protected function getFormElementType($element_type) {
- switch ($element_type) {
- case 'text':
- return 'textarea';
- break;
- default:
- // By default provide text field.
- return 'textfield';
- break;
- }
- }
-
}
diff --git a/lib/Drupal/config_translation/FormElement/Textarea.php b/lib/Drupal/config_translation/FormElement/Textarea.php
new file mode 100644
index 0000000..4c777ef
--- /dev/null
+++ b/lib/Drupal/config_translation/FormElement/Textarea.php
@@ -0,0 +1,27 @@
+ 'textarea',
+ '#default_value' => $value,
+ '#title' => t($definition['label']) . ' (' . $language->name . ')',
+ '#rows' => $rows,
+ '#attributes' => array('lang' => $language->id),
+ );
+ }
+
+}
diff --git a/lib/Drupal/config_translation/FormElement/Textfield.php b/lib/Drupal/config_translation/FormElement/Textfield.php
new file mode 100644
index 0000000..3b19b6a
--- /dev/null
+++ b/lib/Drupal/config_translation/FormElement/Textfield.php
@@ -0,0 +1,21 @@
+ 'textfield',
+ '#default_value' => $value,
+ '#title' => t($definition['label']) . ' (' . $language->name . ')',
+ '#attributes' => array('lang' => $language->id),
+ );
+ }
+
+}