3 namespace Drupal\field\Plugin\migrate\process\d6;
5 use Drupal\migrate\ProcessPluginBase;
6 use Drupal\migrate\MigrateExecutableInterface;
7 use Drupal\migrate\Row;
10 * Set the default field settings.
12 * @MigrateProcessPlugin(
13 * id = "field_formatter_settings_defaults"
16 class FieldFormatterSettingsDefaults extends ProcessPluginBase {
21 * Set field formatter settings when the map didn't map: for date
22 * formatters, the fallback format, for everything else, empty array.
24 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
25 // If the 1 index is set then the map missed.
26 if (isset($value[1])) {
27 $module = $row->getSourceProperty('module');
28 if ($module === 'date') {
29 $value = ['format_type' => 'fallback'];
31 elseif ($module === 'number') {
32 // We have to do the lookup here in the process plugin because for
33 // number we need to calculated the settings based on the type not just
34 // the module which works well for other field types.
35 return $this->numberSettings($row->getDestinationProperty('options/type'), $value[1]);
48 * The format selected for the field on the display.
51 * The correct default settings.
53 * @throws \Drupal\migrate\MigrateException
55 protected function numberSettings($type, $format) {
60 'decimal_separator' => '.',
61 'thousand_separator' => ',',
62 'prefix_suffix' => TRUE,
66 'decimal_separator' => '.',
67 'thousand_separator' => ',',
68 'prefix_suffix' => TRUE,
72 'decimal_separator' => '.',
73 'thousand_separator' => ',',
74 'prefix_suffix' => TRUE,
78 'decimal_separator' => ',',
79 'thousand_separator' => '.',
80 'prefix_suffix' => TRUE,
84 'decimal_separator' => ',',
85 'thousand_separator' => '.',
86 'prefix_suffix' => TRUE,
90 'decimal_separator' => ',',
91 'thousand_separator' => '.',
92 'prefix_suffix' => TRUE,
96 'decimal_separator' => ',',
97 'thousand_separator' => ' ',
98 'prefix_suffix' => TRUE,
102 'decimal_separator' => ',',
103 'thousand_separator' => ' ',
104 'prefix_suffix' => TRUE,
108 'decimal_separator' => ',',
109 'thousand_separator' => ' ',
110 'prefix_suffix' => TRUE,
113 'number_integer' => [
115 'thousand_separator' => ',',
116 'prefix_suffix' => TRUE,
119 'thousand_separator' => '.',
120 'prefix_suffix' => TRUE,
123 'thousand_separator' => ' ',
124 'prefix_suffix' => TRUE,
129 return isset($map[$type][$format]) ? $map[$type][$format] : [];