function TextField::getFieldType

Same name in this branch
  1. 9 core/modules/text/src/Plugin/migrate/field/d6/TextField.php \Drupal\text\Plugin\migrate\field\d6\TextField::getFieldType()
Same name and namespace in other branches
  1. 8.9.x core/modules/text/src/Plugin/migrate/field/d6/TextField.php \Drupal\text\Plugin\migrate\field\d6\TextField::getFieldType()
  2. 8.9.x core/modules/text/src/Plugin/migrate/field/d7/TextField.php \Drupal\text\Plugin\migrate\field\d7\TextField::getFieldType()
  3. 8.9.x core/modules/text/src/Plugin/migrate/cckfield/TextField.php \Drupal\text\Plugin\migrate\cckfield\TextField::getFieldType()
  4. 10 core/modules/text/src/Plugin/migrate/field/d6/TextField.php \Drupal\text\Plugin\migrate\field\d6\TextField::getFieldType()
  5. 10 core/modules/text/src/Plugin/migrate/field/d7/TextField.php \Drupal\text\Plugin\migrate\field\d7\TextField::getFieldType()
  6. 11.x core/modules/text/src/Plugin/migrate/field/d6/TextField.php \Drupal\text\Plugin\migrate\field\d6\TextField::getFieldType()
  7. 11.x core/modules/text/src/Plugin/migrate/field/d7/TextField.php \Drupal\text\Plugin\migrate\field\d7\TextField::getFieldType()

Overrides FieldPluginBase::getFieldType

2 calls to TextField::getFieldType()
TextField::getFieldFormatterType in core/modules/text/src/Plugin/migrate/field/d7/TextField.php
Get the field formatter type from the source.
TextField::getFieldWidgetType in core/modules/text/src/Plugin/migrate/field/d7/TextField.php
Get the field widget type from the source.

File

core/modules/text/src/Plugin/migrate/field/d7/TextField.php, line 67

Class

TextField
Plugin annotation @MigrateField( id = "d7_text", type_map = { "text" = "text", "text_long" = "text_long", "text_with_summary" = "text_with_summary" }, core = {7}, source_module = "text", destination_module = "text", )

Namespace

Drupal\text\Plugin\migrate\field\d7

Code

public function getFieldType(Row $row) {
    $type = $row->getSourceProperty('type');
    $plain_text = FALSE;
    $filtered_text = FALSE;
    foreach ($row->getSourceProperty('instances') as $instance) {
        // Check if this field has plain text instances, filtered text instances,
        // or both.
        $data = unserialize($instance['data']);
        switch ($data['settings']['text_processing']) {
            case '0':
                $plain_text = TRUE;
                break;
            case '1':
                $filtered_text = TRUE;
                break;
        }
    }
    if (in_array($type, [
        'text',
        'text_long',
    ])) {
        // If a text or text_long field has only plain text instances, migrate it
        // to a string or string_long field.
        if ($plain_text && !$filtered_text) {
            $type = str_replace([
                'text',
                'text_long',
            ], [
                'string',
                'string_long',
            ], $type);
        }
        elseif ($plain_text && $filtered_text) {
            $field_name = $row->getSourceProperty('field_name');
            throw new MigrateSkipRowException("Can't migrate source field {$field_name} configured with both plain text and filtered text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
        }
    }
    elseif ($type == 'text_with_summary' && $plain_text) {
        // If a text_with_summary field has plain text instances, skip the row
        // since there's no such thing as a string_with_summary field.
        $field_name = $row->getSourceProperty('field_name');
        throw new MigrateSkipRowException("Can't migrate source field {$field_name} of type text_with_summary configured with plain text processing. See https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#plain-text");
    }
    return $type;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.