diff --git a/model/fieldtypes/HTMLText.php b/model/fieldtypes/HTMLText.php index e0c351089..59244741b 100644 --- a/model/fieldtypes/HTMLText.php +++ b/model/fieldtypes/HTMLText.php @@ -258,12 +258,11 @@ class HTMLText extends Text { * @return boolean */ public function exists() { - // If it's blank, it's blank - if(!parent::exists()) { - return false; - } + $value = $this->value; - $value = $this->RAW(); + if (!$this->isPopulated($value)) { + return false; + } // If it's got a content tag if(preg_match('/<(img|embed|object|iframe|meta|source|link)[^>]*>/i', $value)) { diff --git a/model/fieldtypes/HTMLVarchar.php b/model/fieldtypes/HTMLVarchar.php index 69df13fdc..dfb1531ca 100644 --- a/model/fieldtypes/HTMLVarchar.php +++ b/model/fieldtypes/HTMLVarchar.php @@ -35,7 +35,7 @@ class HTMLVarchar extends Varchar { } public function exists() { - return parent::exists() && $this->RAW() != '

'; + return $this->isPopulated($this->value) && $this->value != '

'; } public function scaffoldFormField($title = null, $params = null) { diff --git a/model/fieldtypes/StringField.php b/model/fieldtypes/StringField.php index 92bfc872a..b2b915258 100644 --- a/model/fieldtypes/StringField.php +++ b/model/fieldtypes/StringField.php @@ -85,9 +85,7 @@ abstract class StringField extends DBField { */ public function exists() { $value = $this->RAW(); - return $value // All truthy values exist - || (is_string($value) && strlen($value)) // non-empty strings exist ('0' but not (int)0) - || (!$this->getNullifyEmpty() && $value === ''); // Remove this stupid exemption in 4.0 + return $this->isPopulated($value); } /** @@ -229,4 +227,16 @@ abstract class StringField extends DBField { public function NoHTML() { return strip_tags($this->RAW()); } + + /** + * Returns true if the value meets all the criteria of not being empty, as defined by + * the class + * @param $value + * @return bool + */ + protected function isPopulated($value) { + return $value // All truthy values exist + || (is_string($value) && strlen($value)) // non-empty strings exist ('0' but not (int)0) + || (!$this->getNullifyEmpty() && $value === ''); // Remove this stupid exemption in 4.0 + } }