Issue #2529144 by phenaproxima: Create cckfield plugin for text fields
parent
df44c00a6c
commit
f30b72571e
|
@ -52,10 +52,6 @@ process:
|
||||||
- type
|
- type
|
||||||
- 'display_settings/format'
|
- 'display_settings/format'
|
||||||
map:
|
map:
|
||||||
text:
|
|
||||||
default: text_default
|
|
||||||
trimmed: text_trimmed
|
|
||||||
plain: basic_string
|
|
||||||
number_integer:
|
number_integer:
|
||||||
default: number_integer
|
default: number_integer
|
||||||
us_0: number_integer
|
us_0: number_integer
|
||||||
|
|
|
@ -36,7 +36,6 @@ process:
|
||||||
bypass: true
|
bypass: true
|
||||||
source: widget_type
|
source: widget_type
|
||||||
map:
|
map:
|
||||||
text_textfield: text_textfield
|
|
||||||
number: number
|
number: number
|
||||||
email_textfield: email_default
|
email_textfield: email_default
|
||||||
date_select: datetime_default
|
date_select: datetime_default
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -87,15 +87,9 @@ class LoadEntity extends PluginBase implements MigrateLoadInterface {
|
||||||
|
|
||||||
if ($source_plugin instanceof CckFieldMigrateSourceInterface) {
|
if ($source_plugin instanceof CckFieldMigrateSourceInterface) {
|
||||||
foreach ($source_plugin->fieldData() as $field_name => $data) {
|
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 {
|
else {
|
||||||
$fields = array_keys($migration->getSourcePlugin()->fields());
|
$fields = array_keys($migration->getSourcePlugin()->fields());
|
||||||
$migration->setProcess($migration->getProcess() + array_combine($fields, $fields));
|
$migration->setProcess($migration->getProcess() + array_combine($fields, $fields));
|
||||||
|
@ -110,45 +104,4 @@ class LoadEntity extends PluginBase implements MigrateLoadInterface {
|
||||||
return $migrations;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue