diff --git a/src/Core/Validation/ValidationResult.php b/src/Core/Validation/ValidationResult.php
index e767be85d9e..9cc0147ebb6 100644
--- a/src/Core/Validation/ValidationResult.php
+++ b/src/Core/Validation/ValidationResult.php
@@ -50,91 +50,52 @@ class ValidationResult
/**
* Is the result valid or not.
* Note that there can be non-error messages in the list.
- *
- * @var bool
*/
- protected $isValid = true;
+ protected bool $isValid = true;
/**
* List of messages
- *
- * @var array
*/
- protected $messages = [];
+ protected array $messages = [];
/**
* Record an error against this validation result,
*
- * @param string $message The message string.
- * @param string $messageType Passed as a CSS class to the form, so other values can be used if desired.
+ * @param $message The message string.
+ * @param $messageType Passed as a CSS class to the form, so other values can be used if desired.
* Standard types are defined by the TYPE_ constant definitions.
- * @param string $code A codename for this error. Only one message per codename will be added.
+ * @param $code A codename for this error. Only one message per codename will be added.
* This can be usedful for ensuring no duplicate messages
- * @param string|bool $cast Cast type; One of the CAST_ constant definitions.
- * Bool values will be treated as plain text flag.
+ * @param $cast Cast type; One of the CAST_ constant definitions.
* @return $this
*/
public function addError(
- $message,
- $messageType = ValidationResult::TYPE_ERROR,
- $code = null,
- $cast = ValidationResult::CAST_TEXT
- ) {
- if ($code === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $code as null is deprecated. Pass a blank string instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $code = '';
- }
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
+ string $message,
+ string $messageType = ValidationResult::TYPE_ERROR,
+ string $code = '',
+ string $cast = ValidationResult::CAST_TEXT,
+ ): static {
return $this->addFieldError('', $message, $messageType, $code, $cast);
}
/**
* Record an error against this validation result,
*
- * @param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
- * @param string $message The message string.
- * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
+ * @param $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
+ * @param $message The message string.
+ * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
* class to the form, so other values can be used if desired.
- * @param string $code A codename for this error. Only one message per codename will be added.
+ * @param $code A codename for this error. Only one message per codename will be added.
* This can be usedful for ensuring no duplicate messages
- * @param string|bool $cast Cast type; One of the CAST_ constant definitions.
- * Bool values will be treated as plain text flag.
- * @return $this
+ * @param $cast Cast type; One of the CAST_ constant definitions.
*/
public function addFieldError(
- $fieldName,
- $message,
- $messageType = ValidationResult::TYPE_ERROR,
- $code = null,
- $cast = ValidationResult::CAST_TEXT,
- ) {
- if ($code === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $code as null is deprecated. Pass a blank string instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $code = '';
- }
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
+ string $fieldName,
+ string $message,
+ string $messageType = ValidationResult::TYPE_ERROR,
+ string $code = '',
+ string $cast = ValidationResult::CAST_TEXT,
+ ): static {
$this->isValid = false;
return $this->addFieldMessage($fieldName, $message, $messageType, $code, $cast);
}
@@ -142,81 +103,42 @@ public function addFieldError(
/**
* Add a message to this ValidationResult without necessarily marking it as an error
*
- * @param string $message The message string.
- * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
+ * @param $message The message string.
+ * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
* class to the form, so other values can be used if desired.
- * @param string $code A codename for this error. Only one message per codename will be added.
+ * @param $code A codename for this error. Only one message per codename will be added.
* This can be usedful for ensuring no duplicate messages
- * @param string|bool $cast Cast type; One of the CAST_ constant definitions.
- * Bool values will be treated as plain text flag.
- * @return $this
+ * @param $cast Cast type; One of the CAST_ constant definitions.
*/
public function addMessage(
- $message,
- $messageType = ValidationResult::TYPE_ERROR,
- $code = null,
- $cast = ValidationResult::CAST_TEXT,
- ) {
- if ($code === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $code as null is deprecated. Pass a blank string instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $code = '';
- }
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
- return $this->addFieldMessage(null, $message, $messageType, $code, $cast);
+ string $message,
+ string $messageType = ValidationResult::TYPE_ERROR,
+ string $code = '',
+ string $cast = ValidationResult::CAST_TEXT,
+ ): static {
+ return $this->addFieldMessage('', $message, $messageType, $code, $cast);
}
/**
* Add a message to this ValidationResult without necessarily marking it as an error
*
- * @param string $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
- * @param string $message The message string.
- * @param string $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
+ * @param $fieldName The field to link the message to. If omitted; a form-wide message is assumed.
+ * @param $message The message string.
+ * @param $messageType The type of message: e.g. "bad", "warning", "good", or "required". Passed as a CSS
* class to the form, so other values can be used if desired.
- * @param string $code A codename for this error. Only one message per codename will be added.
+ * @param $code A codename for this error. Only one message per codename will be added.
* This can be usedful for ensuring no duplicate messages
- * @param string|bool $cast Cast type; One of the CAST_ constant definitions.
- * Bool values will be treated as plain text flag.
- * @return $this
+ * @param $cast Cast type; One of the CAST_ constant definitions.
*/
public function addFieldMessage(
- $fieldName,
- $message,
- $messageType = ValidationResult::TYPE_ERROR,
- $code = null,
- $cast = ValidationResult::CAST_TEXT,
- ) {
- if ($code === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $code as null is deprecated. Pass a blank string instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $code = '';
- }
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
+ string $fieldName,
+ string $message,
+ string $messageType = ValidationResult::TYPE_ERROR,
+ string $code = '',
+ string $cast = ValidationResult::CAST_TEXT,
+ ): static {
if ($code && is_numeric($code)) {
- throw new InvalidArgumentException("Don't use a numeric code '$code'. Use a string.");
- }
- if (is_bool($cast)) {
- $cast = $cast ? ValidationResult::CAST_TEXT : ValidationResult::CAST_HTML;
+ throw new InvalidArgumentException("Don't use a numeric code '$code'. Use a non-numeric code instead.");
}
$metadata = [
'message' => $message,
@@ -229,15 +151,13 @@ public function addFieldMessage(
} else {
$this->messages[] = $metadata;
}
-
return $this;
}
/**
* Returns true if the result is valid.
- * @return boolean
*/
- public function isValid()
+ public function isValid(): bool
{
return $this->isValid;
}
@@ -245,9 +165,9 @@ public function isValid()
/**
* Return the full error meta-data, suitable for combining with another ValidationResult.
*
- * @return array Array of messages, where each item is an array of data for that message.
+ * @return Array of messages, where each item is an array of data for that message.
*/
- public function getMessages()
+ public function getMessages(): array
{
return $this->messages;
}
@@ -257,10 +177,9 @@ public function getMessages()
* It will be valid if both this and the other result are valid.
* This object will be modified to contain the new validation information.
*
- * @param ValidationResult $other the validation result object to combine
- * @return $this
+ * @param $other the validation result object to combine
*/
- public function combineAnd(ValidationResult $other)
+ public function combineAnd(ValidationResult $other): static
{
$this->isValid = $this->isValid && $other->isValid();
$this->messages = array_merge($this->messages, $other->getMessages());
diff --git a/src/Forms/CheckboxField.php b/src/Forms/CheckboxField.php
index 48f1c652e87..90a742e8feb 100644
--- a/src/Forms/CheckboxField.php
+++ b/src/Forms/CheckboxField.php
@@ -21,7 +21,7 @@ public function dataValue()
return ($this->value) ? 1 : null;
}
- public function Value()
+ public function getValue(): mixed
{
return ($this->value) ? 1 : 0;
}
@@ -39,7 +39,7 @@ public function getAttributes()
return array_merge(
$attributes,
[
- 'checked' => ($this->Value()) ? 'checked' : null,
+ 'checked' => ($this->getValue()) ? 'checked' : null,
'type' => 'checkbox',
]
);
diff --git a/src/Forms/CheckboxField_Readonly.php b/src/Forms/CheckboxField_Readonly.php
index f161a66c746..b611d17c311 100644
--- a/src/Forms/CheckboxField_Readonly.php
+++ b/src/Forms/CheckboxField_Readonly.php
@@ -13,7 +13,7 @@ public function performReadonlyTransformation()
return clone $this;
}
- public function Value()
+ public function getFormattedValue(): mixed
{
return $this->value ?
_t('SilverStripe\\Forms\\CheckboxField.YESANSWER', 'Yes') :
diff --git a/src/Forms/ConfirmedPasswordField.php b/src/Forms/ConfirmedPasswordField.php
index 34a084be5a8..e9e594240ef 100644
--- a/src/Forms/ConfirmedPasswordField.php
+++ b/src/Forms/ConfirmedPasswordField.php
@@ -204,7 +204,7 @@ public function Field($properties = [])
}
// Check if the field should be visible up front
- $visible = $this->hiddenField->Value();
+ $visible = $this->hiddenField->getValue();
$classes = $visible
? 'showOnClickContainer'
: 'showOnClickContainer d-none';
@@ -418,7 +418,7 @@ public function setName($name)
public function isSaveable()
{
return !$this->showOnClick
- || ($this->showOnClick && $this->hiddenField && $this->hiddenField->Value());
+ || ($this->showOnClick && $this->hiddenField && $this->hiddenField->getValue());
}
public function validate(): ValidationResult
@@ -432,10 +432,10 @@ public function validate(): ValidationResult
$this->getPasswordField()->setValue($this->value);
$this->getConfirmPasswordField()->setValue($this->confirmValue);
- $value = $this->getPasswordField()->Value();
+ $value = $this->getPasswordField()->getValue();
// both password-fields should be the same
- if ($value != $this->getConfirmPasswordField()->Value()) {
+ if ($value != $this->getConfirmPasswordField()->getValue()) {
$result->addFieldError(
$name,
_t('SilverStripe\\Forms\\Form.VALIDATIONPASSWORDSDONTMATCH', "Passwords don't match"),
@@ -446,7 +446,7 @@ public function validate(): ValidationResult
if (!$this->canBeEmpty) {
// both password-fields shouldn't be empty
- if (!$value || !$this->getConfirmPasswordField()->Value()) {
+ if (!$value || !$this->getConfirmPasswordField()->getValue()) {
$result->addFieldError(
$name,
_t('SilverStripe\\Forms\\Form.VALIDATIONPASSWORDSNOTEMPTY', "Passwords can't be empty"),
diff --git a/src/Forms/DateField.php b/src/Forms/DateField.php
index 914b20f72ea..15efbaf42f4 100644
--- a/src/Forms/DateField.php
+++ b/src/Forms/DateField.php
@@ -343,7 +343,7 @@ public function setValue($value, $data = null)
return $this;
}
- public function Value()
+ public function getFormattedValue(): mixed
{
return $this->internalToFrontend($this->value);
}
diff --git a/src/Forms/DateField_Disabled.php b/src/Forms/DateField_Disabled.php
index be56d92ea5a..bb68af5fd48 100644
--- a/src/Forms/DateField_Disabled.php
+++ b/src/Forms/DateField_Disabled.php
@@ -39,7 +39,7 @@ public function Field($properties = [])
// Render the display value with some complement of info
$displayValue = Convert::raw2xml(sprintf(
$format ?? '',
- $this->Value(),
+ $this->getFormattedValue(),
$infoComplement
));
}
diff --git a/src/Forms/DatetimeField.php b/src/Forms/DatetimeField.php
index cfa1beb012c..e0769ae7470 100644
--- a/src/Forms/DatetimeField.php
+++ b/src/Forms/DatetimeField.php
@@ -362,7 +362,7 @@ public function setValue($value, $data = null)
*
* @return string
*/
- public function Value()
+ public function getFormattedValue(): mixed
{
return $this->internalToFrontend($this->value);
}
diff --git a/src/Forms/DropdownField.php b/src/Forms/DropdownField.php
index 9e31245250f..e0e1ef6067b 100644
--- a/src/Forms/DropdownField.php
+++ b/src/Forms/DropdownField.php
@@ -97,7 +97,7 @@ class DropdownField extends SingleSelectField
protected function getFieldOption($value, $title)
{
// Check selection
- $selected = $this->isSelectedValue($value, $this->Value());
+ $selected = $this->isSelectedValue($value, $this->getValue());
// Check disabled
$disabled = false;
diff --git a/src/Forms/FileField.php b/src/Forms/FileField.php
index fdeed0a59d7..6760ab03de0 100644
--- a/src/Forms/FileField.php
+++ b/src/Forms/FileField.php
@@ -172,7 +172,7 @@ public function saveInto(DataObjectInterface $record)
}
}
- public function Value()
+ public function getValue(): mixed
{
return isset($_FILES[$this->getName()]) ? $_FILES[$this->getName()] : null;
}
diff --git a/src/Forms/FileUploadReceiver.php b/src/Forms/FileUploadReceiver.php
index 3aaa42ff323..90fc6722ada 100644
--- a/src/Forms/FileUploadReceiver.php
+++ b/src/Forms/FileUploadReceiver.php
@@ -237,11 +237,11 @@ public function getItems()
*/
public function getItemIDs()
{
- $value = $this->Value();
+ $value = $this->getValue();
return empty($value['Files']) ? [] : $value['Files'];
}
- public function Value()
+ public function getValue(): mixed
{
// Re-override FileField Value to use data value
return $this->dataValue();
diff --git a/src/Forms/Form.php b/src/Forms/Form.php
index fbcf2425034..0a0eb3c0aa9 100644
--- a/src/Forms/Form.php
+++ b/src/Forms/Form.php
@@ -1186,17 +1186,9 @@ public function FieldMap()
*/
public function sessionMessage($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT)
{
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
$this->setMessage($message, $type, $cast);
$result = $this->getSessionValidationResult() ?: ValidationResult::create();
- $result->addMessage($message, $type, null, $cast);
+ $result->addMessage($message, $type, '', $cast);
$this->setSessionValidationResult($result);
}
@@ -1210,17 +1202,9 @@ public function sessionMessage($message, $type = ValidationResult::TYPE_ERROR, $
*/
public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT)
{
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
$this->setMessage($message, $type, $cast);
$result = $this->getSessionValidationResult() ?: ValidationResult::create();
- $result->addError($message, $type, null, $cast);
+ $result->addError($message, $type, '', $cast);
$this->setSessionValidationResult($result);
}
@@ -1235,17 +1219,9 @@ public function sessionError($message, $type = ValidationResult::TYPE_ERROR, $ca
*/
public function sessionFieldError($message, $fieldName, $type = ValidationResult::TYPE_ERROR, $cast = ValidationResult::CAST_TEXT)
{
- if ($cast === null) {
- Deprecation::notice(
- '5.4.0',
- 'Passing $cast as null is deprecated. Pass a ValidationResult::CAST_* constant instead.',
- Deprecation::SCOPE_GLOBAL
- );
- $cast = ValidationResult::CAST_TEXT;
- }
$this->setMessage($message, $type, $cast);
$result = $this->getSessionValidationResult() ?: ValidationResult::create();
- $result->addFieldMessage($fieldName, $message, $type, null, $cast);
+ $result->addFieldMessage($fieldName, $message, $type, '', $cast);
$this->setSessionValidationResult($result);
}
diff --git a/src/Forms/FormField.php b/src/Forms/FormField.php
index 08301ecb54d..92c2ef4c24e 100644
--- a/src/Forms/FormField.php
+++ b/src/Forms/FormField.php
@@ -269,7 +269,8 @@ class FormField extends RequestHandler implements FieldValidationInterface
'Field' => 'HTMLFragment',
'AttributesHTML' => 'HTMLFragment', // property $AttributesHTML version
'getAttributesHTML' => 'HTMLFragment', // method $getAttributesHTML($arg) version
- 'Value' => 'Text',
+ 'FormattedValue' => 'Text',
+ 'getFormattedValue' => 'Text',
'extraClass' => 'Text',
'ID' => 'Text',
'isReadOnly' => 'Boolean',
@@ -457,14 +458,10 @@ public function getValue(): mixed
/**
* Returns the value of the field which may be modified for display purposes
* for instance to add localisation or formatting.
- *
- * @return mixed
- * @deprecated 5.4.0 Will be replaced by getFormattedValue() and getValue()
*/
- public function Value()
+ public function getFormattedValue(): mixed
{
- Deprecation::notice('5.4.0', 'Will be replaced by getFormattedValue() and getValue()');
- return $this->value;
+ return $this->getValue();
}
/**
@@ -670,7 +667,7 @@ protected function getDefaultAttributes(): array
$attributes = [
'type' => $this->getInputType(),
'name' => $this->getName(),
- 'value' => $this->Value(),
+ 'value' => $this->getFormattedValue(),
'class' => $this->extraClass(),
'id' => $this->ID(),
'disabled' => $this->isDisabled(),
@@ -950,16 +947,12 @@ public function Field($properties = [])
$context = $context->customise($properties);
}
- $result = $context->renderWith($context->getTemplates());
+ $dbHtmlText = $context->renderWith($context->getTemplates());
- // Trim whitespace from the result, so that trailing newlines are suppressed. Works for strings and HTMLText values
- if (is_string($result)) {
- $result = trim($result ?? '');
- } elseif ($result instanceof DBField) {
- $result->setValue(trim($result->getValue() ?? ''));
- }
+ // Trim whitespace from the result, so that trailing newlines are suppressed.
+ $dbHtmlText->setValue(trim($dbHtmlText->getValue() ?? ''));
- return $result;
+ return $dbHtmlText;
}
/**
@@ -1556,7 +1549,7 @@ public function getSchemaStateDefaults()
$state = [
'name' => $this->getName(),
'id' => $this->ID(),
- 'value' => $this->Value(),
+ 'value' => $this->getFormattedValue(),
'message' => $this->getSchemaMessage(),
'data' => [],
];
diff --git a/src/Forms/GridField/GridField.php b/src/Forms/GridField/GridField.php
index 05c204b6dbb..ef7e94d7262 100644
--- a/src/Forms/GridField/GridField.php
+++ b/src/Forms/GridField/GridField.php
@@ -485,7 +485,7 @@ private function addStateFromRequest(): void
// Create a dummy state so that we can merge the current state with the request state.
$newState = new GridState($this, $stateStr);
// Put the current state on top of the request state.
- $newState->setValue($oldState->Value());
+ $newState->setValue($oldState->getValue());
$this->state = $newState;
}
}
diff --git a/src/Forms/GridField/GridFieldStateManager.php b/src/Forms/GridField/GridFieldStateManager.php
index 727077737a3..53ac56b3e05 100644
--- a/src/Forms/GridField/GridFieldStateManager.php
+++ b/src/Forms/GridField/GridFieldStateManager.php
@@ -39,7 +39,7 @@ public function getStateKey(GridField $gridField): string
public function addStateToURL(GridField $gridField, string $url): string
{
$key = $this->getStateKey($gridField);
- $value = $gridField->getState(false)->Value();
+ $value = $gridField->getState(false)->getValue();
// Using a JSON-encoded empty array as the blank value, to avoid changing Value() semantics in a minor release
if ($value === '{}') {
diff --git a/src/Forms/GridField/GridState.php b/src/Forms/GridField/GridState.php
index a5f5725970a..7e97f9f878e 100644
--- a/src/Forms/GridField/GridState.php
+++ b/src/Forms/GridField/GridState.php
@@ -101,10 +101,8 @@ public function getList()
/**
* Returns a json encoded string representation of this state.
- *
- * @return string
*/
- public function Value()
+ public function getValue(): string
{
$data = $this->data ? $this->data->getChangesArray() : [];
return json_encode($data, JSON_FORCE_OBJECT);
@@ -117,7 +115,7 @@ public function Value()
*/
public function dataValue()
{
- return $this->Value();
+ return $this->getValue();
}
/**
@@ -126,11 +124,11 @@ public function dataValue()
*/
public function attrValue()
{
- return Convert::raw2att($this->Value());
+ return Convert::raw2att($this->getValue());
}
public function __toString()
{
- return $this->Value();
+ return $this->getValue();
}
}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField.php b/src/Forms/HTMLEditor/HTMLEditorField.php
index 4527dd1de6a..72e1de842e4 100644
--- a/src/Forms/HTMLEditor/HTMLEditorField.php
+++ b/src/Forms/HTMLEditor/HTMLEditorField.php
@@ -23,7 +23,8 @@ class HTMLEditorField extends TextareaField
{
private static $casting = [
- 'Value' => 'HTMLText',
+ 'FormattedValue' => 'HTMLText',
+ 'getFormattedValue' => 'HTMLText',
];
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_HTML;
@@ -134,7 +135,7 @@ public function saveInto(DataObjectInterface $record)
}
// Sanitise if requested
- $htmlValue = HTMLValue::create($this->Value());
+ $htmlValue = HTMLValue::create($this->getValue());
if (HTMLEditorField::config()->sanitise_server_side) {
$config = $this->getEditorConfig();
$santiser = HTMLEditorSanitiser::create($config);
@@ -184,11 +185,9 @@ public function getSchemaStateDefaults()
}
/**
- * Return value with all values encoded in html entities
- *
- * @return string Raw HTML
+ * Return formatted value with all values encoded in html entities
*/
- public function ValueEntities()
+ public function getFormattedValueEntities(): string
{
$entities = get_html_translation_table(HTML_ENTITIES);
@@ -196,13 +195,13 @@ public function ValueEntities()
$entities[$key] = "/" . $value . "/";
}
- $value = preg_replace_callback($entities, function ($matches) {
+ $formattedValue = preg_replace_callback($entities, function ($matches) {
// Don't apply double encoding to ampersand
$doubleEncoding = $matches[0] != '&';
return htmlentities($matches[0], ENT_COMPAT, 'UTF-8', $doubleEncoding);
- }, $this->Value() ?? '');
+ }, $this->getFormattedValue() ?? '');
- return $value;
+ return $formattedValue;
}
/**
@@ -231,7 +230,7 @@ private function usesXmlFriendlyField(DataObjectInterface $record): bool
}
$castingService = CastingService::singleton();
- $castValue = $castingService->cast($this->Value(), $record, $this->getName());
+ $castValue = $castingService->cast($this->getFormattedValue(), $record, $this->getName());
return $castValue instanceof DBField && $castValue::config()->get('escape_type') === 'xml';
}
}
diff --git a/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php b/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php
index 2f02b71ac67..00b48c3e6e3 100644
--- a/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php
+++ b/src/Forms/HTMLEditor/HTMLEditorField_Readonly.php
@@ -10,7 +10,8 @@
class HTMLEditorField_Readonly extends HTMLReadonlyField
{
private static $casting = [
- 'Value' => 'HTMLText',
+ 'FormattedValue' => 'HTMLText',
+ 'getFormattedValue' => 'HTMLText',
];
public function Type()
diff --git a/src/Forms/HTMLReadonlyField.php b/src/Forms/HTMLReadonlyField.php
index 64bb339e30f..280fca6a51b 100644
--- a/src/Forms/HTMLReadonlyField.php
+++ b/src/Forms/HTMLReadonlyField.php
@@ -10,8 +10,10 @@
class HTMLReadonlyField extends ReadonlyField
{
private static $casting = [
- 'Value' => 'HTMLFragment',
- 'ValueEntities' => 'HTMLFragment',
+ 'FormattedValue' => 'HTMLFragment',
+ 'getFormattedValue' => 'HTMLFragment',
+ 'FormattedValueEntities' => 'HTMLFragment',
+ 'getFormattedValueEntities' => 'HTMLFragment',
];
protected $schemaDataType = HTMLReadonlyField::SCHEMA_DATA_TYPE_STRUCTURAL;
@@ -27,12 +29,12 @@ public function Field($properties = [])
}
/**
- * Return value with all values encoded in html entities
+ * Return formatted value with all values encoded in html entities
*
* @return string Raw HTML
*/
- public function ValueEntities()
+ public function getFormattedValueEntities()
{
- return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
+ return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8');
}
}
diff --git a/src/Forms/ListboxField.php b/src/Forms/ListboxField.php
index 0a2112cae08..ac8d90b040c 100644
--- a/src/Forms/ListboxField.php
+++ b/src/Forms/ListboxField.php
@@ -4,6 +4,8 @@
use SilverStripe\Model\List\ArrayList;
use SilverStripe\Model\ArrayData;
+use SilverStripe\ORM\DB;
+use SilverStripe\ORM\FieldType\DBHTMLText;
/**
* Multi-line listbox field, created from a select tag.
@@ -68,9 +70,6 @@ public function __construct($name, $title = '', $source = [], $value = null, $si
/**
* Returns a select tag containing all the appropriate option tags
- *
- * @param array $properties
- * @return string
*/
public function Field($properties = [])
{
@@ -252,7 +251,7 @@ protected function getOptionsArray($term)
public function getValueArray()
{
- $value = $this->Value();
+ $value = $this->getFormattedValue();
$validValues = $this->getValidValues();
if (empty($validValues)) {
return [];
diff --git a/src/Forms/LiteralField.php b/src/Forms/LiteralField.php
index 0dda550c0c3..82d926bc897 100644
--- a/src/Forms/LiteralField.php
+++ b/src/Forms/LiteralField.php
@@ -18,7 +18,8 @@ class LiteralField extends DatalessField
{
private static $casting = [
- 'Value' => 'HTMLFragment',
+ 'FormattedValue' => 'HTMLFragment',
+ 'getFormattedValue' => 'HTMLFragment',
];
/**
diff --git a/src/Forms/MoneyField.php b/src/Forms/MoneyField.php
index 75e70d61f6a..eb072e2937b 100644
--- a/src/Forms/MoneyField.php
+++ b/src/Forms/MoneyField.php
@@ -219,7 +219,7 @@ public function dataValue()
return $this->getDBMoney()->getValue();
}
- public function Value()
+ public function getFormattedValue(): mixed
{
// Localised money
return $this->getDBMoney()->Nice();
diff --git a/src/Forms/MultiSelectField.php b/src/Forms/MultiSelectField.php
index e3adb61c32e..626689dbf90 100644
--- a/src/Forms/MultiSelectField.php
+++ b/src/Forms/MultiSelectField.php
@@ -39,7 +39,7 @@ abstract class MultiSelectField extends SelectField
*/
public function getValueArray()
{
- return $this->getListValues($this->Value());
+ return $this->getListValues($this->getFormattedValue());
}
/**
diff --git a/src/Forms/NullableField.php b/src/Forms/NullableField.php
index 99669cd0ab8..954a8a45365 100644
--- a/src/Forms/NullableField.php
+++ b/src/Forms/NullableField.php
@@ -17,7 +17,7 @@
* When a form is submitted the field tests the value of the "is null" checkbox and sets its value
* accordingly. You can retrieve the value of the wrapped field from the NullableField as follows:
*
- * $field->Value() or $field->dataValue()
+ * $field->getValue() or $field->dataValue()
*
* You can specify the label to use for the "is null" checkbox. If you want to use i18n for this
* label then specify it like this:
@@ -61,7 +61,7 @@ public function __construct(FormField $valueField, $isNullLabel = null)
parent::__construct(
$valueField->getName(),
$valueField->Title(),
- $valueField->Value()
+ $valueField->getValue()
);
$this->setForm($valueField->getForm());
diff --git a/src/Forms/NumericField.php b/src/Forms/NumericField.php
index cc36e9509dc..320f4def8c8 100644
--- a/src/Forms/NumericField.php
+++ b/src/Forms/NumericField.php
@@ -169,7 +169,7 @@ public function setSubmittedValue($value, $data = null)
*
* @return string
*/
- public function Value()
+ public function getFormattedValue(): mixed
{
// Show invalid value back to user in case of error
if ($this->value === null || $this->value === false) {
diff --git a/src/Forms/OptionsetField.php b/src/Forms/OptionsetField.php
index a966aebe375..53eddd68262 100644
--- a/src/Forms/OptionsetField.php
+++ b/src/Forms/OptionsetField.php
@@ -75,7 +75,7 @@ protected function getFieldOption($value, $title, $odd)
'Name' => $this->getOptionName(),
'Value' => $value,
'Title' => $title,
- 'isChecked' => $this->isSelectedValue($value, $this->Value()),
+ 'isChecked' => $this->isSelectedValue($value, $this->getValue()),
'isDisabled' => $this->isDisabledValue($value)
]);
}
diff --git a/src/Forms/ReadonlyField.php b/src/Forms/ReadonlyField.php
index 68a496a5d61..f8e6badecc4 100644
--- a/src/Forms/ReadonlyField.php
+++ b/src/Forms/ReadonlyField.php
@@ -70,7 +70,7 @@ public function castingHelper(string $field, bool $useFallback = true): ?string
public function getSchemaStateDefaults()
{
$state = parent::getSchemaStateDefaults();
- $state['value'] = $this->dataValue();
+ $state['value'] = $this->getFormattedValue();
return $state;
}
@@ -79,7 +79,7 @@ public function getSchemaStateDefaults()
/**
* @return mixed|string
*/
- public function Value()
+ public function getFormattedValue(): mixed
{
// Get raw value
$value = $this->dataValue();
diff --git a/src/Forms/SearchableDropdownTrait.php b/src/Forms/SearchableDropdownTrait.php
index b5d794726db..a844baa13b6 100644
--- a/src/Forms/SearchableDropdownTrait.php
+++ b/src/Forms/SearchableDropdownTrait.php
@@ -319,7 +319,7 @@ public function getAttributes(): array
*/
public function getValueArray(): array
{
- $value = $this->Value();
+ $value = $this->getValue();
if (empty($value)) {
return [];
}
@@ -474,7 +474,7 @@ private function getDefaultSchemaValue()
if (!$this->getIsLazyLoaded() && $this->hasMethod('getDefaultValue')) {
return $this->getDefaultValue();
}
- return $this->Value();
+ return $this->getValue();
}
private function getOptionsForSearchRequest(string $term): array
diff --git a/src/Forms/SingleLookupField.php b/src/Forms/SingleLookupField.php
index 1bf54b8f24e..bb79eab5133 100644
--- a/src/Forms/SingleLookupField.php
+++ b/src/Forms/SingleLookupField.php
@@ -83,14 +83,13 @@ public function Type()
*
* @return mixed
*/
- public function Value()
+ public function getFormattedValue(): mixed
{
$label = $this->valueToLabel();
if (!is_null($label)) {
return $label;
}
-
- return parent::Value();
+ return parent::getFormattedValue();
}
/**
diff --git a/src/Forms/SingleSelectField.php b/src/Forms/SingleSelectField.php
index b2488c369cf..f8a0126cd78 100644
--- a/src/Forms/SingleSelectField.php
+++ b/src/Forms/SingleSelectField.php
@@ -58,7 +58,7 @@ public function getValueForValidation(): mixed
public function getDefaultValue()
{
- $value = $this->Value();
+ $value = $this->getValue();
$validValues = $this->getValidValues();
// assign value to field, such as first option available
if ($value === null || !in_array($value, $validValues)) {
diff --git a/src/Forms/TextareaField.php b/src/Forms/TextareaField.php
index 713faf9a1a2..d1c54b94175 100644
--- a/src/Forms/TextareaField.php
+++ b/src/Forms/TextareaField.php
@@ -34,8 +34,10 @@ class TextareaField extends FormField
* @var array
*/
private static $casting = [
- 'Value' => 'Text',
- 'ValueEntities' => 'HTMLFragment([\'shortcodes\' => false])',
+ 'FormattedValue' => 'Text',
+ 'getFormattedValue' => 'Text',
+ 'FormattedValueEntities' => 'HTMLFragment([\'shortcodes\' => false])',
+ 'getFormattedValueEntities' => 'HTMLFragment([\'shortcodes\' => false])',
];
protected $schemaDataType = FormField::SCHEMA_DATA_TYPE_TEXT;
@@ -192,9 +194,8 @@ public function getSchemaValidation()
* @return string Raw HTML
* @deprecated 5.4.0 Use getFormattedValueEntities() instead
*/
- public function ValueEntities()
+ public function getFormattedValueEntities(): string
{
- Deprecation::noticeWithNoReplacment('5.4.0', 'Will be replaced by getFormattedValueEntities()');
- return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
+ return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8');
}
}
diff --git a/src/Forms/TimeField.php b/src/Forms/TimeField.php
index 082e11aee8e..1c64bd6828a 100644
--- a/src/Forms/TimeField.php
+++ b/src/Forms/TimeField.php
@@ -280,7 +280,7 @@ public function setValue($value, $data = null)
return $this;
}
- public function Value()
+ public function getFormattedValue(): mixed
{
$localised = $this->internalToFrontend($this->value);
if ($localised) {
diff --git a/src/Forms/TreeDropdownField.php b/src/Forms/TreeDropdownField.php
index 7a8889dafca..69d5c994ba7 100644
--- a/src/Forms/TreeDropdownField.php
+++ b/src/Forms/TreeDropdownField.php
@@ -865,7 +865,7 @@ public function getSchemaStateDefaults()
{
$data = parent::getSchemaStateDefaults();
/** @var Hierarchy|DataObject $record */
- $record = $this->Value() ? $this->objectForKey($this->Value()) : null;
+ $record = $this->getValue() ? $this->objectForKey($this->getValue()) : null;
$data['data']['cacheKey'] = $this->getCacheKey();
$data['data']['showSelectedPath'] = $this->getShowSelectedPath();
diff --git a/src/Forms/TreeMultiselectField.php b/src/Forms/TreeMultiselectField.php
index 449a275fe45..48e8c8b9aad 100644
--- a/src/Forms/TreeMultiselectField.php
+++ b/src/Forms/TreeMultiselectField.php
@@ -121,7 +121,7 @@ public function getSchemaStateDefaults()
*/
public function getItems()
{
- $value = $this->Value();
+ $value = $this->getValue();
// If unchanged, load from record
if ($value === 'unchanged') {
diff --git a/src/Forms/Validation/Validator.php b/src/Forms/Validation/Validator.php
index 04df3d263cb..e36a85b80da 100644
--- a/src/Forms/Validation/Validator.php
+++ b/src/Forms/Validation/Validator.php
@@ -83,7 +83,7 @@ public function validationError(
$messageType = ValidationResult::TYPE_ERROR,
$cast = ValidationResult::CAST_TEXT
) {
- $this->result->addFieldError($fieldName, $message, $messageType, null, $cast);
+ $this->result->addFieldError($fieldName, $message, $messageType, '', $cast);
return $this;
}
diff --git a/templates/SilverStripe/Forms/GridField/GridField_Item.ss b/templates/SilverStripe/Forms/GridField/GridField_Item.ss
index c57cd94df2f..d14aabc5e1b 100644
--- a/templates/SilverStripe/Forms/GridField/GridField_Item.ss
+++ b/templates/SilverStripe/Forms/GridField/GridField_Item.ss
@@ -1,12 +1,12 @@
<% if $GridField.ExtraColumnsCount %>
<% loop $Fields %>
-