Skip to content

Commit

Permalink
API Rename FormField Value to getFormattedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 14, 2025
1 parent 83e8cbe commit ab7d1ca
Show file tree
Hide file tree
Showing 60 changed files with 150 additions and 154 deletions.
4 changes: 2 additions & 2 deletions src/Forms/CheckboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function dataValue()
return ($this->value) ? 1 : null;
}

public function Value()
public function getValue(): mixed
{
return ($this->value) ? 1 : 0;
}
Expand All @@ -39,7 +39,7 @@ public function getAttributes()
return array_merge(
$attributes,
[
'checked' => ($this->Value()) ? 'checked' : null,
'checked' => ($this->getValue()) ? 'checked' : null,
'type' => 'checkbox',
]
);
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/CheckboxField_Readonly.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function performReadonlyTransformation()
return clone $this;
}

public function Value()
public function getFormattedValue(): string
{
return $this->value ?
_t('SilverStripe\\Forms\\CheckboxField.YESANSWER', 'Yes') :
Expand Down
10 changes: 5 additions & 5 deletions src/Forms/ConfirmedPasswordField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/DateField.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function setValue($value, $data = null)
return $this;
}

public function Value()
public function getFormattedValue(): string
{
return $this->internalToFrontend($this->value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/DateField_Disabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/DatetimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public function setValue($value, $data = null)
*
* @return string
*/
public function Value()
public function getFormattedValue(): string
{
return $this->internalToFrontend($this->value);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/DropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/FileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/FileUploadReceiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
// Re-override FileField Value to use data value
return $this->dataValue();
Expand Down
8 changes: 3 additions & 5 deletions src/Forms/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,8 @@ 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
*/
public function Value()
public function getFormattedValue(): string
{
return $this->value;
}
Expand Down Expand Up @@ -668,7 +666,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(),
Expand Down Expand Up @@ -1554,7 +1552,7 @@ public function getSchemaStateDefaults()
$state = [
'name' => $this->getName(),
'id' => $this->ID(),
'value' => $this->Value(),
'value' => $this->getFormattedValue(),
'message' => $this->getSchemaMessage(),
'data' => [],
];
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/GridField/GridFieldStateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 === '{}') {
Expand Down
10 changes: 4 additions & 6 deletions src/Forms/GridField/GridState.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -117,7 +115,7 @@ public function Value()
*/
public function dataValue()
{
return $this->Value();
return $this->getValue();
}

/**
Expand All @@ -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();
}
}
6 changes: 3 additions & 3 deletions src/Forms/HTMLEditor/HTMLEditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,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);
Expand Down Expand Up @@ -200,7 +200,7 @@ public function ValueEntities()
// Don't apply double encoding to ampersand
$doubleEncoding = $matches[0] != '&';
return htmlentities($matches[0], ENT_COMPAT, 'UTF-8', $doubleEncoding);
}, $this->Value() ?? '');
}, $this->getValue() ?? '');

return $value;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ private function usesXmlFriendlyField(DataObjectInterface $record): bool
}

$castingService = CastingService::singleton();
$castValue = $castingService->cast($this->Value(), $record, $this->getName());
$castValue = $castingService->cast($this->getValue(), $record, $this->getName());
return $castValue instanceof DBField && $castValue::config()->get('escape_type') === 'xml';
}
}
2 changes: 1 addition & 1 deletion src/Forms/HTMLReadonlyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public function Field($properties = [])
*/
public function ValueEntities()
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8');
}
}
2 changes: 1 addition & 1 deletion src/Forms/ListboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected function getOptionsArray($term)

public function getValueArray()
{
$value = $this->Value();
$value = $this->getValue();
$validValues = $this->getValidValues();
if (empty($validValues)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/MoneyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public function dataValue()
return $this->getDBMoney()->getValue();
}

public function Value()
public function getFormattedValue(): string
{
// Localised money
return $this->getDBMoney()->Nice();
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/MultiSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class MultiSelectField extends SelectField
*/
public function getValueArray()
{
return $this->getListValues($this->Value());
return $this->getListValues($this->getValue());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/NullableField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/NumericField.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function setSubmittedValue($value, $data = null)
*
* @return string
*/
public function Value()
public function getFormattedValue(): string
{
// Show invalid value back to user in case of error
if ($this->value === null || $this->value === false) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/OptionsetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/ReadonlyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getSchemaStateDefaults()
/**
* @return mixed|string
*/
public function Value()
public function getFormattedValue(): string
{
// Get raw value
$value = $this->dataValue();
Expand Down
4 changes: 2 additions & 2 deletions src/Forms/SearchableDropdownTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public function getAttributes(): array
*/
public function getValueArray(): array
{
$value = $this->Value();
$value = $this->getValue();
if (empty($value)) {
return [];
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/SingleLookupField.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function Type()
*
* @return mixed
*/
public function Value()
public function getFormattedValue(): string
{
$label = $this->valueToLabel();
if (!is_null($label)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/SingleSelectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/TextareaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,6 @@ public function getSchemaValidation()
*/
public function ValueEntities()
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
return htmlentities($this->getFormattedValue() ?? '', ENT_COMPAT, 'UTF-8');
}
}
2 changes: 1 addition & 1 deletion src/Forms/TimeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function setValue($value, $data = null)
return $this;
}

public function Value()
public function getFormattedValue(): string
{
$localised = $this->internalToFrontend($this->value);
if ($localised) {
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/TreeDropdownField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Forms/TreeMultiselectField.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function getSchemaStateDefaults()
*/
public function getItems()
{
$value = $this->Value();
$value = $this->getValue();

// If unchanged, load from record
if ($value === 'unchanged') {
Expand Down
2 changes: 1 addition & 1 deletion templates/SilverStripe/Forms/CheckboxSetField.ss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<% if $Options.Count %>
<% loop $Options %>
<li class="$Class" role="$Role">
<input id="$ID" class="checkbox" name="$Name" type="checkbox" value="$Value.ATT"<% if $isChecked %> checked="checked"<% end_if %><% if $isDisabled %> disabled="disabled"<% end_if %> />
<input id="$ID" class="checkbox" name="$Name" type="checkbox" value="$FormattedValue.ATT"<% if $isChecked %> checked="checked"<% end_if %><% if $isDisabled %> disabled="disabled"<% end_if %> />
<label for="$ID">$Title</label>
</li>
<% end_loop %>
Expand Down
Loading

0 comments on commit ab7d1ca

Please sign in to comment.