Permalink
Browse files

Fix issue #98 rzelnik multi-lang fields fatal error when converting T…

…itle to TitleLanguage and only 1 language in system
  • Loading branch information...
1 parent 5b89842 commit ae114cea694ad1d955eb434e611ada25ee45dbb9 @ryancramerdesign committed Apr 23, 2012
@@ -37,6 +37,7 @@ class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageIn
// convert it to a LanguagesPageFieldValue
$str = (string) $value;
$value = $page->getUnformatted($field->name);
+ if(is_string($value)) $value = new LanguagesPageFieldValue($value); // #98
$value->setLanguageValue(wire('user')->language->id, $str);
}
return $value;
@@ -141,7 +141,8 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
}
wire('config')->dateFormat = $this->_('Y-m-d H:i:s'); // Sortable date format used in the admin
- setlocale(LC_ALL, $this->_('C')); // Value to pass to PHP's setlocale(LC_ALL, 'value') function when initializing this language // Default is: C
+ $locale = $this->_('C'); // Value to pass to PHP's setlocale(LC_ALL, 'value') function when initializing this language // Default is 'C'. Specify '0' to skip the setlocale() call (and carry on system default).
+ if($locale != '0') setlocale(LC_ALL, $locale);
// setup our hooks handled by this class
$this->addHookBefore('Inputfield::render', $this, 'hookInputfieldBeforeRender');
@@ -240,7 +241,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
if($this->LanguageSupportFields && strpos($name, '_') && wire('fields')->get($name)) {
$language = $this->LanguageSupportFields->getAlternateFieldLanguage($name);
if($language && $language->id) {
- $event->return = $this->wrapInputfieldOutput($event->return, $inputfield->attr('id'), $language->title);
+ $label = (string) $language->title;
+ if(!strlen($label)) $label = $language->name;
+ $event->return = $this->wrapInputfieldOutput($event->return, $inputfield->attr('id'), $label);
return;
}
}
@@ -275,7 +278,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
$o = $inputfield->___render();
}
- $out .= $this->wrapInputfieldOutput($o, $newID, $language->title);
+ $label = (string) $language->title;
+ if(!strlen($label)) $label = $language->name;
+ $out .= $this->wrapInputfieldOutput($o, $newID, $label);
}
$inputfield->setAttribute('name', $name);
@@ -386,6 +391,9 @@ class LanguageSupport extends WireData implements Module, ConfigurableModule {
if($page->template->name != self::languageTemplateName) return;
// trigger hook in $languages
+ $ids = $this->otherLanguagePageIDs;
+ $ids[] = $page->id;
+ $this->set('otherLanguagePageIDs', $ids);
wire('languages')->added($page);
// save this as a known language page with module settings
@@ -29,8 +29,10 @@ class LanguagesPageFieldValue extends Wire {
/**
* Construct the multi language value
*
+ * @param array|string $values
+ *
*/
- public function __construct(array $values = null) {
+ public function __construct($values = null) { // #98
$languageSupport = wire('modules')->get('LanguageSupport');
$this->defaultLanguagePageID = $languageSupport->defaultLanguagePageID;

0 comments on commit ae114ce

Please sign in to comment.