FileField.php 1.3 KB
Newer Older
1 2 3 4 5 6 7 8
<?php

namespace Drupal\file\Plugin\migrate\field\d6;

use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;

9 10
// cspell:ignore imagefield imagelink

11 12 13
/**
 * @MigrateField(
 *   id = "filefield",
14 15 16
 *   core = {6},
 *   source_module = "filefield",
 *   destination_module = "file"
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
 * )
 */
class FileField extends FieldPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getFieldWidgetMap() {
    return [
      'filefield_widget' => 'file_generic',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldFormatterMap() {
    return [
      'default' => 'file_default',
      'url_plain' => 'file_url_plain',
      'path_plain' => 'file_url_plain',
      'image_plain' => 'image',
      'image_nodelink' => 'image',
      'image_imagelink' => 'image',
    ];
  }

  /**
   * {@inheritdoc}
   */
47
  public function defineValueProcessPipeline(MigrationInterface $migration, $field_name, $data) {
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    $process = [
      'plugin' => 'd6_field_file',
      'source' => $field_name,
    ];
    $migration->mergeProcessOfProperty($field_name, $process);
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldType(Row $row) {
    return $row->getSourceProperty('widget_type') == 'imagefield_widget' ? 'image' : 'file';
  }

}