public function FieldCollectionFieldInstanceSettings::transform in Paragraphs 8
Performs the associated process.
Parameters
mixed $value: The value to be transformed.
\Drupal\migrate\MigrateExecutableInterface $migrate_executable: The migration in which this process is being executed.
\Drupal\migrate\Row $row: The row from the source to process. Normally, just transforming the value is adequate but very rarely you might need to change two columns at the same time or something like that.
string $destination_property: The destination property currently worked on. This is only used together with the $row above.
Return value
string|array The newly transformed value.
Overrides ProcessPluginBase::transform
File
- src/
Plugin/ migrate/ process/ FieldCollectionFieldInstanceSettings.php, line 22
Class
- FieldCollectionFieldInstanceSettings
- Configure field instance settings for field collections.
Namespace
Drupal\paragraphs\Plugin\migrate\processCode
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$type = $row
->getSourceProperty('type');
if ($type == 'field_collection') {
$bundles = $this->entityTypeBundleInfo
->getBundleInfo('paragraph');
$target_bundle = $row
->getSourceProperty('field_name');
// Remove field_ prefix for new bundle.
$target_bundle = substr($target_bundle, FieldCollection::FIELD_COLLECTION_PREFIX_LENGTH);
if (!isset($bundles[$target_bundle])) {
throw new MigrateSkipRowException('No target paragraph bundle found for field_collection');
}
// Enable only this paragraph type for this field.
$weight = 0;
$value['handler_settings']['negate'] = 0;
$value['handler_settings']['target_bundles'] = [
$target_bundle => $target_bundle,
];
$value['handler_settings']['target_bundles_drag_drop'][$target_bundle] = [
'enabled' => TRUE,
'weight' => ++$weight,
];
unset($bundles[$target_bundle]);
foreach ($bundles as $bundle_name => $bundle) {
$value['handler_settings']['target_bundles_drag_drop'][$bundle_name] = [
'enabled' => FALSE,
'weight' => ++$weight,
];
unset($bundles[$bundle_name]);
}
}
return $value;
}