mirror of
https://github.com/silverstripe/silverstripe-translatable
synced 2024-10-22 11:05:59 +02:00
Merge branch '1.0'
Conflicts: .travis.yml composer.json
This commit is contained in:
commit
e2c1a7111e
0
_config.php
Normal file
0
_config.php
Normal file
@ -523,7 +523,7 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
// 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 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
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 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
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 @@ class Translatable extends DataExtension implements PermissionProvider {
|
||||
->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 @@ class Translatable_Transformation extends FormTransformation {
|
||||
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;
|
||||
}
|
||||
|
||||
function transformFormField(FormField $field) {
|
||||
public function transformFormField(FormField $field) {
|
||||
$newfield = $field->performReadOnlyTransformation();
|
||||
return $this->baseTransform($newfield, $field);
|
||||
$fn = 'transform' . $field->class;
|
||||
return $this->hasMethod($fn) ? $this->$fn($newfield, $field) : $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 @@ class Translatable_Transformation extends FormTransformation {
|
||||
$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;
|
||||
|
Loading…
Reference in New Issue
Block a user