FieldInstanceWidgetSettings.php 2.28 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\migrate_drupal\Plugin\migrate\process\d6\FieldInstanceWidgetSettings
6 7
 */

8
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Get the field instance widget settings.
 *
 * @MigrateProcessPlugin(
 *   id = "field_instance_widget_settings"
 * )
 */
class FieldInstanceWidgetSettings extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   *
   * Get the field instance default/mapped widget settings.
   */
  public function transform($value, MigrateExecutable $migrate_executable, Row $row, $destination_property) {
    list($widget_type, $widget_settings) = $value;
    return $this->getSettings($widget_type, $widget_settings);
  }

  /**
   * Merge the default D8 and specified D6 settings for a widget type.
   *
   * @param string $widget_type
   *   The widget type.
   * @param array $widget_settings
   *   The widget settings from D6 for this widget.
   *
   * @return array
   *   A valid array of settings.
   */
  public function getSettings($widget_type, $widget_settings) {
    $progress = isset($widget_settings['progress_indicator']) ? $widget_settings['progress_indicator'] : 'throbber';
    $size = isset($widget_settings['size']) ? $widget_settings['size'] : 60;
    $rows = isset($widget_settings['rows']) ? $widget_settings['rows'] : 5;

    $settings = array(
      'text_textfield' => array(
        'size' => $size,
        'placeholder' => '',
      ),
      'text_textarea' => array(
        'rows' => $rows,
        'placeholder' => '',
      ),
      'number' => array(
        'placeholder' => '',
      ),
      'email_textfield' => array(
        'placeholder' => '',
      ),
      'link' => array(
65
        'placeholder_url' => '',
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
        'placeholder_title' => '',
      ),
      'filefield_widget' => array(
        'progress_indicator' => $progress,
      ),
      'imagefield_widget' => array(
        'progress_indicator' => $progress,
        'preview_image_style' => 'thumbnail',
      ),
      'optionwidgets_onoff' => array(
        'display_label' => FALSE,
      ),
      'phone_textfield' => array(
        'placeholder' => '',
      ),
    );

    return isset($settings[$widget_type]) ? $settings[$widget_type] : array();
  }

}