Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '1.0'

Conflicts:
	.travis.yml
	composer.json
  • Loading branch information...
commit e2c1a7111ebde434b4593fa44a62a31ca26e1080 2 parents 7f9dd3e + 9579748
Ingo Schommer chillu authored
Showing with 58 additions and 18 deletions.
  1. 0  _config.php
  2. +58 −18 code/model/Translatable.php
0  _config.php
View
No changes.
76 code/model/Translatable.php
View
@@ -523,7 +523,7 @@ function setOwner($owner, $ownerBaseClass = null) {
// setting translatable fields by inspecting owner - this should really be done in the constructor
if($this->owner && $this->translatableFields === null) {
$this->translatableFields = array_merge(
- array_keys($this->owner->inheritedDatabaseFields()),
+ array_keys($this->owner->db()),
array_keys($this->owner->has_many()),
array_keys($this->owner->many_many()),
array_keys($this->owner->has_one())
@@ -1087,6 +1087,8 @@ protected function addTranslatableFields(&$fields) {
if(preg_match('/_original$/', $dataField->getName())) continue;
// Field already has been transformed
if(isset($allDataFields[$dataField->getName() . '_original'])) continue;
+ // CheckboxField which is already transformed
+ if(preg_match('/class=\"originalvalue\"/', $dataField->Title())) continue;
if(in_array($dataField->getName(), $translatableFieldNames)) {
// if the field is translatable, perform transformation
@@ -1155,8 +1157,14 @@ function getTranslations($locale = null, $stage = null) {
if($this->owner->exists()) {
// HACK need to disable language filtering in augmentSQL(),
// as we purposely want to get different language
- self::disable_locale_filter();
-
+ // also save state of locale-filter, revert to this state at the
+ // end of this method
+ $localeFilterEnabled = false;
+ if(self::locale_filter_enabled()) {
+ self::disable_locale_filter();
+ $localeFilterEnabled = true;
+ }
+
$translationGroupID = $this->getTranslationGroup();
$baseDataClass = ClassInfo::baseDataClass($this->owner->class);
@@ -1185,7 +1193,10 @@ function getTranslations($locale = null, $stage = null) {
->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause);
}
- self::enable_locale_filter();
+ // only re-enable locale-filter if it was enabled at the beginning of this method
+ if($localeFilterEnabled) {
+ self::enable_locale_filter();
+ }
return $translations;
}
@@ -1731,23 +1742,47 @@ function getOriginal() {
return $this->original;
}
- /**
- * @todo transformTextareaField() not used at the moment
- */
- function transformTextareaField(TextareaField $field) {
- $nonEditableField = new ToggleField($fieldname,$field->Title(),'','+','-');
- $nonEditableField->labelMore = '+';
- $nonEditableField->labelLess = '-';
- return $this->baseTransform($nonEditableField, $field);
-
- return $nonEditableField;
+ public function transformFormField(FormField $field) {
+ $newfield = $field->performReadOnlyTransformation();
+ $fn = 'transform' . $field->class;
+ return $this->hasMethod($fn) ? $this->$fn($newfield, $field) : $this->baseTransform($newfield, $field);
}
- function transformFormField(FormField $field) {
- $newfield = $field->performReadOnlyTransformation();
- return $this->baseTransform($newfield, $field);
+ /**
+ * Transform a translatable CheckboxField to show the field value from the default language
+ * in the label.
+ *
+ * @param FormField $nonEditableField The readonly field to contain the original value
+ * @param FormField $originalField The original editable field containing the translated value
+ * @return CheckboxField The field with a modified label
+ */
+ protected function transformCheckboxField(CheckboxField $nonEditableField, CheckboxField $originalField) {
+ $label = $originalField->Title();
+ $fieldName = $originalField->getName();
+ $value = ($this->original->$fieldName)
+ ? _t('Translatable_Transform.CheckboxValueYes', 'Yes')
+ : _t('Translatable_Transform.CheckboxValueNo', 'No');
+ $originalLabel = _t(
+ 'Translatable_Transform.OriginalCheckboxLabel',
+ 'Original: {value}',
+ 'Addition to a checkbox field label showing the original value of the translatable field.',
+ array('value'=>$value)
+ );
+ $originalField->setTitle($label . ' <span class="originalvalue">(' . $originalLabel . ')</span>');
+ return $originalField;
}
+ /**
+ * Transform a translatable field to show the field value from the default language
+ * DataObject below the translated field.
+ *
+ * This is a fallback function which handles field types that aren't transformed by
+ * $this->transform{FieldType} functions.
+ *
+ * @param FormField $nonEditableField The readonly field to contain the original value
+ * @param FormField $originalField The original editable field containing the translated value
+ * @return \CompositeField The transformed field
+ */
protected function baseTransform($nonEditableField, $originalField) {
$fieldname = $originalField->getName();
@@ -1757,7 +1792,12 @@ protected function baseTransform($nonEditableField, $originalField) {
$nonEditableField->setValue($this->original->$fieldname);
$nonEditableField->setName($fieldname.'_original');
$nonEditableField->addExtraClass('originallang');
- $nonEditableField->setTitle('Original '.$originalField->Title());
+ $nonEditableField->setTitle(_t(
+ 'Translatable_Transform.OriginalFieldLabel',
+ 'Original {title}',
+ 'Label for the original value of the translatable field.',
+ array('title'=>$originalField->Title())
+ ));
$nonEditableField_holder->insertBefore($originalField, $fieldname.'_original');
return $nonEditableField_holder;
Please sign in to comment.
Something went wrong with that request. Please try again.