diff --git a/_config.php b/_config.php index 082b7df..5268130 100644 --- a/_config.php +++ b/_config.php @@ -9,8 +9,8 @@ * translatable module is a requirement: https://github.com/silverstripe/silverstripe-translatable */ -if(!defined('TRANSLATABLE_COLUMN_SEPARATOR')){ - define('TRANSLATABLE_COLUMN_SEPARATOR', '__'); +if (!defined('TRANSLATABLE_COLUMN_SEPARATOR')) { + define('TRANSLATABLE_COLUMN_SEPARATOR', '__'); } SiteTree::add_extension('TranslatableUtility'); diff --git a/code/TranslatableFormFieldTransformation.php b/code/TranslatableFormFieldTransformation.php index 4c449d7..13875c6 100644 --- a/code/TranslatableFormFieldTransformation.php +++ b/code/TranslatableFormFieldTransformation.php @@ -1,4 +1,5 @@ setName($fieldname.'_holder'); + $nonEditableField_holder->setName($fieldname . '_holder'); $nonEditableField_holder->addExtraClass('originallang_holder'); $nonEditableField->setValue($this->original->$fieldname); - $nonEditableField->setName($fieldname.'_original'); + $nonEditableField->setName($fieldname . '_original'); $nonEditableField->addExtraClass('originallang'); $nonEditableField->setTitle(_t( - 'Translatable_Transform.OriginalFieldLabel', - 'Original {title}', - 'Label for the original value of the translatable field.', - array('title'=>$originalField->Title()) + 'Translatable_Transform.OriginalFieldLabel', + 'Original {title}', + 'Label for the original value of the translatable field.', + array('title' => $originalField->Title()) )); - $nonEditableField_holder->insertBefore($originalField, $fieldname.'_original'); + $nonEditableField_holder->insertBefore($originalField, $fieldname . '_original'); return $nonEditableField_holder; } } diff --git a/code/extensions/TranslatableDataObject.php b/code/extensions/TranslatableDataObject.php index a111648..d7fc3eb 100644 --- a/code/extensions/TranslatableDataObject.php +++ b/code/extensions/TranslatableDataObject.php @@ -1,4 +1,5 @@ getBasename($fieldName); $localizedFieldName = self::localized_field($fieldName, $locale); @@ -325,7 +327,8 @@ public function getLocalizedFieldName($fieldName) * @param string $fieldName the name of the relation without any locale extension. Eg. "Attachment" * @return bool */ - public function isLocalizedRelation($fieldName){ + public function isLocalizedRelation($fieldName) + { return isset(self::$localizedFields[$this->ownerBaseClass . '_has_one'][$fieldName]); } @@ -334,15 +337,16 @@ public function isLocalizedRelation($fieldName){ * @param string $fieldName the name of the field without any locale extension. Eg. "Title" * @param boolean $strict if false, this will fallback to the master version of the field! */ - public function getLocalizedRelation($fieldName, $strict = true){ + public function getLocalizedRelation($fieldName, $strict = true) + { $localizedField = $this->getLocalizedFieldName($fieldName); - if($strict){ + if ($strict) { return $this->owner->getRelation($localizedField); } // if not strict, check localized first and fallback to fieldname - if($value = $this->owner->getRelation($localizedField)){ + if ($value = $this->owner->getRelation($localizedField)) { return $value; } @@ -663,12 +667,13 @@ protected static function collectDBFields($class) * @param string $class * @return array */ - protected static function collectHasOneRelations($class){ - if(isset(self::$collectorCache[$class . '_has_one'])){ + protected static function collectHasOneRelations($class) + { + if (isset(self::$collectorCache[$class . '_has_one'])) { return self::$collectorCache[$class . '_has_one']; } - if(isset(self::$collectorLock[$class . '_has_one']) && self::$collectorLock[$class . '_has_one']){ + if (isset(self::$collectorLock[$class . '_has_one']) && self::$collectorLock[$class . '_has_one']) { return null; } self::$collectorLock[$class . '_has_one'] = true; @@ -683,7 +688,7 @@ protected static function collectHasOneRelations($class){ $locales = self::get_target_locales(); // remove the default locale - if(($index = array_search(Translatable::default_locale(), $locales)) !== false) { + if (($index = array_search(Translatable::default_locale(), $locales)) !== false) { array_splice($locales, $index, 1); } @@ -691,18 +696,18 @@ protected static function collectHasOneRelations($class){ $fieldsToTranslate = array(); // validate the arguments - if($arguments){ - foreach($arguments as $field){ + if ($arguments) { + foreach ($arguments as $field) { // only allow fields that are actually in our field list - if(array_key_exists($field, $fields)){ + if (array_key_exists($field, $fields)) { $fieldsToTranslate[] = $field; } } } else { // check for the given default field types and add all fields of that type - foreach($fields as $field => $type){ + foreach ($fields as $field => $type) { $typeClean = (($p = strpos($type, '(')) !== false) ? substr($type, 0, $p) : $type; - if(in_array($typeClean, self::$default_field_types)){ + if (in_array($typeClean, self::$default_field_types)) { $fieldsToTranslate[] = $field; } } @@ -712,9 +717,9 @@ protected static function collectHasOneRelations($class){ // gather all the DB fields $additionalFields = array(); self::$localizedFields[$class . '_has_one'] = array(); - foreach($fieldsToTranslate as $field){ + foreach ($fieldsToTranslate as $field) { self::$localizedFields[$class . '_has_one'][$field] = array(); - foreach($locales as $locale){ + foreach ($locales as $locale) { $localizedName = self::localized_field($field, $locale); self::$localizedFields[$class . '_has_one'][$field][] = $localizedName; $additionalFields[$localizedName] = $fields[$field]; @@ -727,7 +732,6 @@ protected static function collectHasOneRelations($class){ } - /** * Get the locales that should be translated * @return array containing the locales to use @@ -770,10 +774,11 @@ protected static function get_arguments($class) /** * Setter for relation specific FormField. Will be cloned in scaffolding functions - * @param string $fieldName + * @param string $fieldName * @param FormField $field */ - public function setFieldForRelation($fieldName, FormField $field) { + public function setFieldForRelation($fieldName, FormField $field) + { if (self::isLocalizedRelation($fieldName)) { self::$localizedFields[$this->ownerBaseClass . '_has_one'][$fieldName]['FormField'] = $field; } @@ -782,7 +787,8 @@ public function setFieldForRelation($fieldName, FormField $field) { /** * @param $fieldName */ - public function getFieldForRelation($fieldName){ + public function getFieldForRelation($fieldName) + { if (self::isLocalizedRelation($fieldName) && array_key_exists('FormField', self::$localizedFields[$this->ownerBaseClass . '_has_one'][$fieldName])) { return self::$localizedFields[$this->ownerBaseClass . '_has_one'][$fieldName]['FormField']; diff --git a/code/extensions/TranslatableUtility.php b/code/extensions/TranslatableUtility.php index 600ec15..880f9d2 100644 --- a/code/extensions/TranslatableUtility.php +++ b/code/extensions/TranslatableUtility.php @@ -1,4 +1,5 @@ * *
* * @@ -98,9 +99,9 @@ public function Languages() 'RFC1766' => i18n::convert_rfc1766($locale), // the language 2 letter code (eg. EN) 'Language' => DBField::create_field('Varchar', - strtoupper(i18n::get_lang_from_locale($locale))), + strtoupper(i18n::get_lang_from_locale($locale))), // the language as written in its native language - 'Title' => DBField::create_field('Varchar', html_entity_decode( + 'Title' => DBField::create_field('Varchar', html_entity_decode( i18n::get_language_name(i18n::get_lang_from_locale($locale), true), ENT_NOQUOTES, 'UTF-8' )), // linking mode (useful for css class) diff --git a/code/extensions/TranslatedFile.php b/code/extensions/TranslatedFile.php index a565589..99d35a2 100644 --- a/code/extensions/TranslatedFile.php +++ b/code/extensions/TranslatedFile.php @@ -1,4 +1,5 @@ sort($sortField)); } else {