BUGFIX Passing $name in MoneyField->FieldCurrency() (fixes #5982, thanks andersw) (from r110835)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112848 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-19 01:34:31 +00:00
parent 61bb2fe4a4
commit 9d4d7301a2

View File

@ -31,7 +31,7 @@ class MoneyField extends FormField {
function __construct($name, $title = null, $value = "", $form = null) { function __construct($name, $title = null, $value = "", $form = null) {
// naming with underscores to prevent values from actually being saved somewhere // naming with underscores to prevent values from actually being saved somewhere
$this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount')); $this->fieldAmount = new NumericField("{$name}[Amount]", _t('MoneyField.FIELDLABELAMOUNT', 'Amount'));
$this->fieldCurrency = $this->FieldCurrency(); $this->fieldCurrency = $this->FieldCurrency($name);
parent::__construct($name, $title, $value, $form); parent::__construct($name, $title, $value, $form);
} }
@ -47,19 +47,20 @@ class MoneyField extends FormField {
} }
/** /**
* @param string $name - Name of field
* @return FormField * @return FormField
*/ */
protected function FieldCurrency() { protected function FieldCurrency($name) {
$allowedCurrencies = $this->getAllowedCurrencies(); $allowedCurrencies = $this->getAllowedCurrencies();
if($allowedCurrencies) { if($allowedCurrencies) {
$field = new DropdownField( $field = new DropdownField(
"{$this->name}[Currency]", "{$name}[Currency]",
_t('MoneyField.FIELDLABELCURRENCY', 'Currency'), _t('MoneyField.FIELDLABELCURRENCY', 'Currency'),
ArrayLib::is_associative($allowedCurrencies) ? $allowedCurrencies : array_combine($allowedCurrencies,$allowedCurrencies) ArrayLib::is_associative($allowedCurrencies) ? $allowedCurrencies : array_combine($allowedCurrencies,$allowedCurrencies)
); );
} else { } else {
$field = new TextField( $field = new TextField(
"{$this->name}[Currency]", "{$name}[Currency]",
_t('MoneyField.FIELDLABELCURRENCY', 'Currency') _t('MoneyField.FIELDLABELCURRENCY', 'Currency')
); );
} }
@ -136,7 +137,7 @@ class MoneyField extends FormField {
// @todo Has to be done twice in case allowed currencies changed since construction // @todo Has to be done twice in case allowed currencies changed since construction
$oldVal = $this->fieldCurrency->Value(); $oldVal = $this->fieldCurrency->Value();
$this->fieldCurrency = $this->FieldCurrency(); $this->fieldCurrency = $this->FieldCurrency($this->name);
$this->fieldCurrency->setValue($oldVal); $this->fieldCurrency->setValue($oldVal);
} }