src/Forms/MoneyField.php
protected function buildCurrencyField()
    {
        $name = $this->getName();

        // Validate allowed currencies
        $currencyValue = $this->fieldCurrency ? $this->fieldCurrency->dataValue() : null;
        $allowedCurrencies = $this->getAllowedCurrencies();
        if (count($allowedCurrencies) === 1) {
            // Hidden field for single currency
            $field = HiddenField::create("{$name}[Currency]");
            reset($allowedCurrencies);
            $currencyValue = key($allowedCurrencies);
        } elseif ($allowedCurrencies) {
            // Dropdown field for multiple currencies
            $field = DropdownField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency'),
                $allowedCurrencies
            );
        } else {
            // Free-text entry for currency value
            $field = TextField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency')
            );
        }

        $field->setReadonly($this->isReadonly());
        $field->setDisabled($this->isDisabled());
        if ($currencyValue) {
            $field->setValue($currencyValue);
        }
        $this->fieldCurrency = $field;
        return $field;
    }
protected function buildCurrencyField()
    {
        $name = $this->getName();

        // Validate allowed currencies
        $currencyValue = $this->fieldCurrency ? $this->fieldCurrency->dataValue() : null;
        $allowedCurrencies = $this->getAllowedCurrencies();
        if (count($allowedCurrencies) === 1) {
            // Hidden field for single currency
            $field = HiddenField::create("{$name}[Currency]");
            reset($allowedCurrencies);
            $currencyValue = key($allowedCurrencies);
        } elseif ($allowedCurrencies) {
            // Dropdown field for multiple currencies
            $field = DropdownField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency'),
                $allowedCurrencies
            );
        } else {
            // Free-text entry for currency value
            $field = TextField::create(
                "{$name}[Currency]",
                _t('SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY', 'Currency')
            );
        }

        $field->setReadonly($this->isReadonly());
        $field->setDisabled($this->isDisabled());
        if ($currencyValue) {
            $field->setValue($currencyValue);
        }
        $this->fieldCurrency = $field;
        return $field;
    }
protected function buildCurrencyField ( ) { $ name = $ this -> getName ( ) ; // Validate allowed currencies $ currencyValue = $ this -> fieldCurrency ? $ this -> fieldCurrency -> dataValue ( ) : null ; $ allowedCurrencies = $ this -> getAllowedCurrencies ( ) ; if ( count ( $ allowedCurrencies ) === 1 ) { // Hidden field for single currency $ field = HiddenField :: create ( "{$name}[Currency]" ) ; reset ( $ allowedCurrencies ) ; $ currencyValue = key ( $ allowedCurrencies ) ; } elseif ( $ allowedCurrencies ) { // Dropdown field for multiple currencies $ field = DropdownField :: create ( "{$name}[Currency]" , _t ( 'SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY' , 'Currency' ) , $ allowedCurrencies ) ; } else { // Free-text entry for currency value $ field = TextField :: create ( "{$name}[Currency]" , _t ( 'SilverStripe\\Forms\\MoneyField.FIELDLABELCURRENCY' , 'Currency' ) ) ; } $ field -> setReadonly ( $ this -> isReadonly ( ) ) ; $ field -> setDisabled ( $ this -> isDisabled ( ) ) ; if ( $ currencyValue ) { $ field -> setValue ( $ currencyValue ) ; } $ this -> fieldCurrency = $ field ; return $ field ; }
Builds a new currency field based on the allowed currencies configured

@return FormField
Builds a new currency field based on the allowed currencies configured