View source
<?php
namespace Drupal\range\Plugin\migrate\process\d6;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
class RangeFieldFormatterSettings extends ProcessPluginBase {
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
list($module, $format) = $value;
$type = $row
->getDestinationProperty('options/type');
$map = [
'range_decimal' => [
'default' => [
'field_prefix_suffix' => TRUE,
],
'us_0' => [
'scale' => 0,
'decimal_separator' => '.',
'thousand_separator' => ',',
'field_prefix_suffix' => TRUE,
],
'us_1' => [
'scale' => 1,
'decimal_separator' => '.',
'thousand_separator' => ',',
'field_prefix_suffix' => TRUE,
],
'us_2' => [
'scale' => 2,
'decimal_separator' => '.',
'thousand_separator' => ',',
'field_prefix_suffix' => TRUE,
],
'be_0' => [
'scale' => 0,
'decimal_separator' => ',',
'thousand_separator' => '.',
'field_prefix_suffix' => TRUE,
],
'be_1' => [
'scale' => 1,
'decimal_separator' => ',',
'thousand_separator' => '.',
'field_prefix_suffix' => TRUE,
],
'be_2' => [
'scale' => 2,
'decimal_separator' => ',',
'thousand_separator' => '.',
'field_prefix_suffix' => TRUE,
],
'fr_0' => [
'scale' => 0,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'field_prefix_suffix' => TRUE,
],
'fr_1' => [
'scale' => 1,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'field_prefix_suffix' => TRUE,
],
'fr_2' => [
'scale' => 2,
'decimal_separator' => ',',
'thousand_separator' => ' ',
'field_prefix_suffix' => TRUE,
],
],
'range_integer' => [
'default' => [
'field_prefix_suffix' => TRUE,
],
'us_0' => [
'thousand_separator' => ',',
'field_prefix_suffix' => TRUE,
],
'be_0' => [
'thousand_separator' => '.',
'field_prefix_suffix' => TRUE,
],
'fr_0' => [
'thousand_separator' => ' ',
'field_prefix_suffix' => TRUE,
],
],
'range_unformatted' => [
'unformatted' => [
'field_prefix_suffix' => TRUE,
],
],
];
return $map[$type][$format] ?? [];
}
}