mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-06 01:31:22 +02:00
Merge pull request #8144 from open-sausages/pulls/3/the-big-shortcode
NEW: StringField exists() checks don't have to use RAW()
This commit is contained in:
commit
3139b246d9
@ -258,12 +258,11 @@ class HTMLText extends Text {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function exists() {
|
public function exists() {
|
||||||
// If it's blank, it's blank
|
$value = $this->value;
|
||||||
if(!parent::exists()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$value = $this->RAW();
|
if (!$this->isPopulated($value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// If it's got a content tag
|
// If it's got a content tag
|
||||||
if(preg_match('/<(img|embed|object|iframe|meta|source|link)[^>]*>/i', $value)) {
|
if(preg_match('/<(img|embed|object|iframe|meta|source|link)[^>]*>/i', $value)) {
|
||||||
|
@ -35,7 +35,7 @@ class HTMLVarchar extends Varchar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function exists() {
|
public function exists() {
|
||||||
return parent::exists() && $this->RAW() != '<p></p>';
|
return $this->isPopulated($this->value) && $this->value != '<p></p>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scaffoldFormField($title = null, $params = null) {
|
public function scaffoldFormField($title = null, $params = null) {
|
||||||
|
@ -85,9 +85,7 @@ abstract class StringField extends DBField {
|
|||||||
*/
|
*/
|
||||||
public function exists() {
|
public function exists() {
|
||||||
$value = $this->RAW();
|
$value = $this->RAW();
|
||||||
return $value // All truthy values exist
|
return $this->isPopulated($value);
|
||||||
|| (is_string($value) && strlen($value)) // non-empty strings exist ('0' but not (int)0)
|
|
||||||
|| (!$this->getNullifyEmpty() && $value === ''); // Remove this stupid exemption in 4.0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -229,4 +227,16 @@ abstract class StringField extends DBField {
|
|||||||
public function NoHTML() {
|
public function NoHTML() {
|
||||||
return strip_tags($this->RAW());
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user