@@ -79,7 +79,7 @@ public static function create(ContainerInterface $container, array $configuratio
7979 public static function defaultSettings () {
8080 return [
8181 'strip_trailing_zeroes ' => FALSE ,
82- 'display_currency_code ' => FALSE ,
82+ 'currency_display ' => ' symbol ' ,
8383 ] + parent ::defaultSettings ();
8484 }
8585
@@ -93,10 +93,15 @@ public function settingsForm(array $form, FormStateInterface $form_state) {
9393 '#title ' => $ this ->t ('Strip trailing zeroes after the decimal point. ' ),
9494 '#default_value ' => $ this ->getSetting ('strip_trailing_zeroes ' ),
9595 ];
96- $ elements ['display_currency_code ' ] = [
97- '#type ' => 'checkbox ' ,
98- '#title ' => $ this ->t ('Display the currency code instead of the currency symbol. ' ),
99- '#default_value ' => $ this ->getSetting ('display_currency_code ' ),
96+ $ elements ['currency_display ' ] = [
97+ '#type ' => 'radios ' ,
98+ '#title ' => $ this ->t ('Currency display ' ),
99+ '#options ' => [
100+ 'symbol ' => $ this ->t ('Symbol (e.g. "$") ' ),
101+ 'code ' => $ this ->t ('Currency code (e.g. "USD") ' ),
102+ 'none ' => $ this ->t ('None ' ),
103+ ],
104+ '#default_value ' => $ this ->getSetting ('currency_display ' ),
100105 ];
101106
102107 return $ elements ;
@@ -113,12 +118,16 @@ public function settingsSummary() {
113118 else {
114119 $ summary [] = $ this ->t ('Do not strip trailing zeroes after the decimal point. ' );
115120 }
116- if ($ this ->getSetting ('display_currency_code ' )) {
117- $ summary [] = $ this ->t ('Display the currency code instead of the currency symbol. ' );
118- }
119- else {
120- $ summary [] = $ this ->t ('Display the currency symbol. ' );
121- }
121+
122+ $ currency_display = $ this ->getSetting ('currency_display ' );
123+ $ currency_display_options = [
124+ 'symbol ' => $ this ->t ('Symbol (e.g. "$") ' ),
125+ 'code ' => $ this ->t ('Currency code (e.g. "USD") ' ),
126+ 'none ' => $ this ->t ('None ' ),
127+ ];
128+ $ summary [] = $ this ->t ('Currency display: @currency_display. ' , [
129+ '@currency_display ' => $ currency_display_options [$ currency_display ],
130+ ]);
122131
123132 return $ summary ;
124133 }
@@ -151,13 +160,12 @@ public function viewElements(FieldItemListInterface $items, $langcode) {
151160 * The formatting options.
152161 */
153162 protected function getFormattingOptions () {
154- $ options = [];
163+ $ options = [
164+ 'currency_display ' => $ this ->getSetting ('currency_display ' ),
165+ ];
155166 if ($ this ->getSetting ('strip_trailing_zeroes ' )) {
156167 $ options ['minimum_fraction_digits ' ] = 0 ;
157168 }
158- if ($ this ->getSetting ('display_currency_code ' )) {
159- $ options ['currency_display ' ] = 'code ' ;
160- }
161169
162170 return $ options ;
163171 }
0 commit comments