Skip to content

Commit

Permalink
Allow better subclassing of MoneyField
Browse files Browse the repository at this point in the history
Move generation of NumberField from constructor to method to allow override in subclass.
  • Loading branch information
beerbohmdo committed Feb 16, 2024
1 parent bcbbfdd commit 8ffa23e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Forms/MoneyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ public function getAmountField()
public function __construct($name, $title = null, $value = "")
{
$this->setName($name);
$this->fieldAmount = NumericField::create(
"{$name}[Amount]",
_t('SilverStripe\\Forms\\MoneyField.FIELDLABELAMOUNT', 'Amount')
)
->setScale(2);
$this->buildAmountField();
$this->buildCurrencyField();

parent::__construct($name, $title, $value);
Expand All @@ -75,6 +71,18 @@ public function __clone()
$this->fieldCurrency = clone $this->fieldCurrency;
}

/**
* @return void
*/
protected function buildAmountField()
{
$this->fieldAmount = NumericField::create(
"{$this->name}[Amount]",
_t('SilverStripe\\Forms\\MoneyField.FIELDLABELAMOUNT', 'Amount')
)
->setScale(2);
}

/**
* Builds a new currency field based on the allowed currencies configured
*
Expand Down

0 comments on commit 8ffa23e

Please sign in to comment.