Here is how I was able to achieve it.
Paragraph Migration:
id: fup_balance_csv_import
....
....
process:
field_upload: field_upload
field_download: field_download
field_total: field_total
destination:
plugin: entity_reference_revisions:paragraph
default_bundle: fup_balance
Node Migration:
id: subscription_list_csv_import
.............
........
process:
# Paragraphs field.
pseudo_field_fup_details:
-
plugin: migration_lookup
migration: fup_balance_csv_import
source: title # Unique idetifier.
field_fup_details:
-
plugin: sub_process
source:
- '@pseudo_field_fup_details'
process:
target_id: '0'
target_revision_id: '1'
This is by using the standard Migration Process. Sometimes it might not be helpful then you need to write your own migration plugin. Below is the way to do it.
# Paragraphs Field.
field_country_time_zones:
-
plugin: country_timezones_paragraphs
source:
field_1: source_field_1
field_2: source_field_2
Migration Plugin :
<?php
namespace Drupal\countries_list_migration\Plugin\migrate\process;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
/**
* Provides a countries_timezones migration plugin.
*
* Usage:
*
* @code
* process:
* bar:
* plugin: country_timezones_paragraphs
* source: source_field_name
* @endcode
*
* @MigrateProcessPlugin(
* id = "country_timezones_paragraphs",
* handle_multiples = TRUE
* )
*/
class CountryTimezonesParagraphs extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $logger;
/**
* Constructs a CountriesTimezones plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* The logger service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger->get('countries_list_migration');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('logger.factory')
);
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$paragraphs =[];
if (isset($value)) {
$paragraphs[] = $this->createCountryTimezonesParagraphsItem($value);
}
return $paragraphs;
}
/**
* {@inheritdoc}
*/
public function multiple(): bool {
return TRUE;
}
protected function createCountryTimezonesParagraphsItem(array $item): array {
$paragraph = Paragraph::create([
'type' => 'country_timezones',
'field_1' => [
'value' => $item['field_1'],
],
'field_2' => [
'value' => $item['field_2'],
],
]);
$paragraph->save();
return [
'target_id' => $paragraph->id(),
'target_revision_id' => $paragraph->getRevisionId(),
];
}
}
Hope its Helpful.