mirror of
https://github.com/processwire/processwire.git
synced 2025-08-12 17:54:44 +02:00
Minor updates in LanguagesPageFieldValue to correct warnings under some rare cases
This commit is contained in:
@@ -88,8 +88,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
*/
|
*/
|
||||||
public function wired() {
|
public function wired() {
|
||||||
parent::wired();
|
parent::wired();
|
||||||
$this->languageSupport = $this->wire()->modules->get('LanguageSupport');
|
$this->languageSupport();
|
||||||
$this->defaultLanguagePageID = $this->languageSupport->defaultLanguagePageID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,13 +130,16 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
|
|
||||||
if(array_key_exists('data', $values)) {
|
if(array_key_exists('data', $values)) {
|
||||||
if(is_null($values['data'])) $values['data'] = '';
|
if(is_null($values['data'])) $values['data'] = '';
|
||||||
$this->data[$this->defaultLanguagePageID] = $values['data'];
|
$this->data[$this->defaultLanguagePageID()] = $values['data'];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($this->languageSupport->otherLanguagePageIDs as $id) {
|
$languageSupport = $this->languageSupport();
|
||||||
$key = 'data' . $id;
|
if($languageSupport) {
|
||||||
$value = empty($values[$key]) ? '' : $values[$key];
|
foreach($languageSupport->otherLanguagePageIDs as $id) {
|
||||||
$this->data[$id] = $value;
|
$key = 'data' . $id;
|
||||||
|
$value = empty($values[$key]) ? '' : $values[$key];
|
||||||
|
$this->data[$id] = $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,10 +215,13 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value in the default language
|
* Returns the value in the default language
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getDefaultValue() {
|
public function getDefaultValue() {
|
||||||
return $this->data[$this->defaultLanguagePageID];
|
$id = $this->defaultLanguagePageID();
|
||||||
|
return isset($this->data[$id]) ? $this->data[$id] : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -271,7 +276,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
|
|
||||||
$template = $this->page->template;
|
$template = $this->page->template;
|
||||||
$language = $this->wire()->user->language;
|
$language = $this->wire()->user->language;
|
||||||
$defaultValue = (string) $this->data[$this->defaultLanguagePageID];
|
$defaultValue = (string) $this->data[$this->defaultLanguagePageID()];
|
||||||
|
|
||||||
if(!$language || !$language->id || $language->isDefault()) return $defaultValue;
|
if(!$language || !$language->id || $language->isDefault()) return $defaultValue;
|
||||||
if($template && $template->noLang) return $defaultValue;
|
if($template && $template->noLang) return $defaultValue;
|
||||||
@@ -281,7 +286,7 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
if(!strlen($languageValue)) {
|
if(!strlen($languageValue)) {
|
||||||
// value is blank
|
// value is blank
|
||||||
if($this->field) {
|
if($this->field) {
|
||||||
if($this->field->langBlankInherit == self::langBlankInheritDefault) {
|
if($this->field->get('langBlankInherit') == self::langBlankInheritDefault) {
|
||||||
// inherit value from default language
|
// inherit value from default language
|
||||||
$languageValue = $defaultValue;
|
$languageValue = $defaultValue;
|
||||||
}
|
}
|
||||||
@@ -385,6 +390,28 @@ class LanguagesPageFieldValue extends Wire implements LanguagesValueInterface, \
|
|||||||
public function getIterator() {
|
public function getIterator() {
|
||||||
return new \ArrayObject($this->data);
|
return new \ArrayObject($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return null|LanguageSupport
|
||||||
|
* @throws WireException
|
||||||
|
* @throws WirePermissionException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function languageSupport() {
|
||||||
|
if($this->languageSupport) return $this->languageSupport;
|
||||||
|
$this->languageSupport = $this->wire()->modules->get('LanguageSupport');
|
||||||
|
$this->defaultLanguagePageID = $this->languageSupport->defaultLanguagePageID;
|
||||||
|
return $this->languageSupport;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function defaultLanguagePageID() {
|
||||||
|
if(!$this->defaultLanguagePageID) $this->languageSupport();
|
||||||
|
return $this->defaultLanguagePageID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user