Skip to content

Commit

Permalink
API Deprecate FormField Value
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jan 27, 2025
1 parent 0aa00a6 commit be6374a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/Forms/FormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,36 @@ public function getInputType()
return $this->inputType;
}

/**
* Returns the internal value of the field
*
* @return mixed
*/
public function getValue()
{
return $this->value;
}

/**
* Returns the value of the field which may be modified for display purposes
* for instance to add localisation or formatting.
*/
public function getFormattedValue(): mixed
{
return $this->getValue();
}

/**
* Returns the field value.
*
* @see FormField::setSubmittedValue()
* @return mixed
* @deprecated 5.4.0 Use getFormattedValue() or getValue() instead
*/
public function Value()
{
return $this->value;
Deprecation::notice('5.4.0', 'Use getFormattedValue() or getValue() instead');
return $this->getFormattedValue();
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/Forms/TextareaField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace SilverStripe\Forms;

use SilverStripe\Dev\Deprecation;

/**
* TextareaField creates a multi-line text field,
* allowing more data to be entered than a standard
Expand Down Expand Up @@ -202,13 +204,23 @@ public function getSchemaValidation()
return $rules;
}

/**
* Return value with all values encoded in html entities
*/
public function getFormattedValueEntities(): string
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
}

/**
* Return value with all values encoded in html entities
*
* @return string Raw HTML
* @deprecated 5.4.0 Use getFormattedValueEntities() instead
*/
public function ValueEntities()
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8');
Deprecation::noticeWithNoReplacment('5.4.0', 'Use getFormattedValueEntities() instead');
return $this->getFormattedValueEntities();
}
}

0 comments on commit be6374a

Please sign in to comment.