1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 11:44:42 +02:00

Fix issue processwire/processwire-issues#492 where FieldtypeTextareaLanguage fields on multi-language install with only default language present could get caught in a loop during load of field

This commit is contained in:
Ryan Cramer
2018-02-12 09:12:43 -05:00
parent 1f6ae656dc
commit ef6a9d56e4

View File

@@ -25,6 +25,11 @@ class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLa
/** /**
* Sanitize value for storage * Sanitize value for storage
* *
* @param Page $page
* @param Field $field
* @param LanguagesPageFieldValue|string|array $value
* @return LanguagesPageFieldValue
*
*/ */
public function sanitizeValue(Page $page, Field $field, $value) { public function sanitizeValue(Page $page, Field $field, $value) {
if(is_object($value) && $value instanceof LanguagesPageFieldValue) { if(is_object($value) && $value instanceof LanguagesPageFieldValue) {
@@ -33,9 +38,9 @@ class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLa
// convert it to a LanguagesPageFieldValue // convert it to a LanguagesPageFieldValue
if(is_array($value)) $value = reset($value); if(is_array($value)) $value = reset($value);
$str = (string) $value; $str = (string) $value;
$value = $page->getUnformatted($field->name); $value = $page->data($field->name);
if(is_string($value) || is_array($value)) { if(!is_object($value)) { // string, array or null
$value = new LanguagesPageFieldValue($page, $field, $value); // #98 $value = new LanguagesPageFieldValue($page, $field, $value);
} }
$value->setLanguageValue($this->wire('user')->language->id, $str); $value->setLanguageValue($this->wire('user')->language->id, $str);
} }
@@ -45,6 +50,9 @@ class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLa
/** /**
* Return the database schema in specified format * Return the database schema in specified format
* *
* @param Field $field
* @return array
*
*/ */
public function getDatabaseSchema(Field $field) { public function getDatabaseSchema(Field $field) {
$schema = parent::getDatabaseSchema($field); $schema = parent::getDatabaseSchema($field);
@@ -60,6 +68,11 @@ class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLa
/** /**
* Format value for output, basically typcasting to a string and sending to textformatters from FieldtypeTextarea * Format value for output, basically typcasting to a string and sending to textformatters from FieldtypeTextarea
* *
* @param Page $page
* @param Field $field
* @param string|LanguagesPageFieldValue $value
* @return string
*
*/ */
public function formatValue(Page $page, Field $field, $value) { public function formatValue(Page $page, Field $field, $value) {
return parent::formatValue($page, $field, (string) $value); return parent::formatValue($page, $field, (string) $value);