Version 1
[yaffs-website] / web / core / modules / field / src / Plugin / migrate / process / d6 / FieldInstanceWidgetSettings.php
1 <?php
2
3 namespace Drupal\field\Plugin\migrate\process\d6;
4
5 use Drupal\migrate\MigrateExecutableInterface;
6 use Drupal\migrate\ProcessPluginBase;
7 use Drupal\migrate\Row;
8
9 /**
10  * Get the field instance widget settings.
11  *
12  * @MigrateProcessPlugin(
13  *   id = "field_instance_widget_settings"
14  * )
15  */
16 class FieldInstanceWidgetSettings extends ProcessPluginBase {
17
18   /**
19    * {@inheritdoc}
20    *
21    * Get the field instance default/mapped widget settings.
22    */
23   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
24     list($widget_type, $widget_settings) = $value;
25     return $this->getSettings($widget_type, $widget_settings);
26   }
27
28   /**
29    * Merge the default D8 and specified D6 settings for a widget type.
30    *
31    * @param string $widget_type
32    *   The widget type.
33    * @param array $widget_settings
34    *   The widget settings from D6 for this widget.
35    *
36    * @return array
37    *   A valid array of settings.
38    */
39   public function getSettings($widget_type, $widget_settings) {
40     $progress = isset($widget_settings['progress_indicator']) ? $widget_settings['progress_indicator'] : 'throbber';
41     $size = isset($widget_settings['size']) ? $widget_settings['size'] : 60;
42     $rows = isset($widget_settings['rows']) ? $widget_settings['rows'] : 5;
43
44     $settings = [
45       'text_textfield' => [
46         'size' => $size,
47         'placeholder' => '',
48       ],
49       'text_textarea' => [
50         'rows' => $rows,
51         'placeholder' => '',
52       ],
53       'number' => [
54         'placeholder' => '',
55       ],
56       'email_textfield' => [
57         'placeholder' => '',
58       ],
59       'link' => [
60         'placeholder_url' => '',
61         'placeholder_title' => '',
62       ],
63       'filefield_widget' => [
64         'progress_indicator' => $progress,
65       ],
66       'imagefield_widget' => [
67         'progress_indicator' => $progress,
68         'preview_image_style' => 'thumbnail',
69       ],
70       'optionwidgets_onoff' => [
71         'display_label' => FALSE,
72       ],
73       'phone_textfield' => [
74         'placeholder' => '',
75       ],
76     ];
77
78     return isset($settings[$widget_type]) ? $settings[$widget_type] : [];
79   }
80
81 }