Issue #2529144 by phenaproxima: Create cckfield plugin for text fields

8.0.x
Alex Pott 2015-07-16 23:18:11 +01:00
parent df44c00a6c
commit f30b72571e
4 changed files with 72 additions and 53 deletions

View File

@ -52,10 +52,6 @@ process:
- type
- 'display_settings/format'
map:
text:
default: text_default
trimmed: text_trimmed
plain: basic_string
number_integer:
default: number_integer
us_0: number_integer

View File

@ -36,7 +36,6 @@ process:
bypass: true
source: widget_type
map:
text_textfield: text_textfield
number: number
email_textfield: email_default
date_select: datetime_default

View File

@ -0,0 +1,71 @@
<?php
/**
* @file
* Contains \Drupal\migrate_drupal\Plugin\migrate\cckfield\TextField.
*/
namespace Drupal\migrate_drupal\Plugin\migrate\cckfield;
use Drupal\migrate\Entity\MigrationInterface;
/**
* @PluginID("text")
*/
class TextField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldWidgetMap() {
return [
'text_textfield' => 'text_textfield',
];
}
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
return [
'default' => 'text_default',
'trimmed' => 'text_trimmed',
'plain' => 'basic_string',
];
}
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
// The data is stored differently depending on whether we're using
// db storage.
$value_key = $data['db_storage'] ? $field_name : "$field_name/value";
$format_key = $data['db_storage'] ? $field_name . '_format' : "$field_name/format" ;
$migration->setProcessOfProperty("$field_name/value", $value_key);
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
$process = [
[
'plugin' => 'static_map',
'bypass' => TRUE,
'source' => $format_key,
'map' => [0 => NULL]
],
[
'plugin' => 'skip_on_empty',
'method' => 'process',
],
[
'plugin' => 'migration',
'migration' => 'd6_filter_format',
'source' => $format_key,
],
];
$migration->mergeProcessOfProperty("$field_name/format", $process);
}
}

View File

@ -87,13 +87,7 @@ class LoadEntity extends PluginBase implements MigrateLoadInterface {
if ($source_plugin instanceof CckFieldMigrateSourceInterface) {
foreach ($source_plugin->fieldData() as $field_name => $data) {
switch ($data['type']) {
case 'text':
$this->processTextField($field_name, $data, $migration);
break;
default:
$migration->setProcessOfProperty($field_name, $field_name);
}
$migration->setProcessOfProperty($field_name, $field_name);
}
}
else {
@ -110,45 +104,4 @@ class LoadEntity extends PluginBase implements MigrateLoadInterface {
return $migrations;
}
/**
* Manipulate text fields with any per field type processing.
*
* @param string $field_name
* The field we're processing.
* @param array $field_data
* The an array of field type data from the source.
* @param \Drupal\migrate\Entity\MigrationInterface $migration
* The migration entity.
*/
protected function processTextField($field_name, $field_data, MigrationInterface $migration) {
// The data is stored differently depending on whether we're using
// db storage.
$value_key = $field_data['db_storage'] ? $field_name : "$field_name/value";
$format_key = $field_data['db_storage'] ? $field_name . '_format' : "$field_name/format" ;
$migration->setProcessOfProperty("$field_name/value", $value_key);
// See \Drupal\migrate_drupal\Plugin\migrate\source\d6\User::baseFields(),
// signature_format for an example of the YAML that represents this
// process array.
$process = [
[
'plugin' => 'static_map',
'bypass' => TRUE,
'source' => $format_key,
'map' => [0 => NULL]
],
[
'plugin' => 'skip_on_empty',
'method' => 'process',
],
[
'plugin' => 'migration',
'migration' => 'd6_filter_format',
'source' => $format_key,
],
];
$migration->mergeProcessOfProperty("$field_name/format", $process);
}
}