private function MigrationDefinitionCreator::setFieldDefinition in GatherContent 8.5
Set field definition.
1 call to MigrationDefinitionCreator::setFieldDefinition()
- MigrationDefinitionCreator::setDefinitionFieldProperties in src/
MigrationDefinitionCreator.php - Set the field process and destination properties.
File
- src/
MigrationDefinitionCreator.php, line 461
Class
- MigrationDefinitionCreator
- Create dynamic migration definitions.
Namespace
Drupal\gathercontentCode
private function setFieldDefinition(array &$definition, array $data, $elementId, $element, EntityInterface $fieldInfo = NULL, string $fieldType, EntityInterface $targetFieldInfo = NULL, bool $isTranslatable, bool $isMultiple) {
switch ($fieldType) {
case 'image':
case 'file':
$fileDir = $fieldInfo
->getSetting('file_directory');
$uriScheme = $fieldInfo
->getFieldStorageDefinition()
->getSetting('uri_scheme') . '://';
$definition['process'][$element] = [
'plugin' => 'gather_content_file',
'source' => $elementId,
'uri_scheme' => $uriScheme,
'file_dir' => $fileDir,
'language' => $this->siteDefaultLangCode,
];
if ($definition['langcode'] == 'und') {
$definition['process'][$element]['language'] = 'und';
}
break;
case 'timestamp':
$definition['process'][$element] = [
'plugin' => 'callback',
'callable' => 'strtotime',
];
break;
case 'date':
case 'datetime':
$definition['process'][$element][] = [
'plugin' => 'callback',
'callable' => 'strtotime',
];
$definition['process'][$element][] = [
'plugin' => 'format_date',
'from_format' => 'U',
'to_format' => DateTimeItemInterface::DATETIME_STORAGE_FORMAT,
];
break;
case 'text':
case 'text_long':
case 'text_with_summary':
$this
->setTextFieldDefinition($definition, $element, $elementId, $isMultiple);
$this
->setTextFormat($definition, $data, $elementId, $element, $isMultiple);
break;
case 'entity_reference':
if (!empty($fieldInfo
->getSetting('handler_settings')['auto_create_bundle'])) {
$bundle = $fieldInfo
->getSetting('handler_settings')['auto_create_bundle'];
}
else {
$handler_settings = $fieldInfo
->getSetting('handler_settings');
$handler_settings = reset($handler_settings);
$bundle = array_shift($handler_settings);
}
$definition['process'][$element] = [
'plugin' => 'sub_process',
'source' => $elementId,
'process' => [
'target_id' => [
'plugin' => 'gather_content_taxonomy',
'bundle' => $bundle,
'source' => 'gc_id',
],
],
];
break;
case 'entity_reference_revisions':
$targetEntityBundle = $targetFieldInfo
->getTargetBundle();
$language = $this->siteDefaultLangCode;
if (isset($data['language'])) {
$language = $data['language'];
}
$this->collectedReferences[$definition['id']][$element][$targetEntityBundle]['data']['language'] = $language;
$this->collectedReferences[$definition['id']][$element][$targetEntityBundle]['data']['elements'][$elementId] = $data['elements'][$elementId];
if (!empty($data['element_text_formats'][$elementId])) {
$this->collectedReferences[$definition['id']][$element][$targetEntityBundle]['data']['element_text_formats'][$elementId] = $data['element_text_formats'][$elementId];
}
$this->collectedReferences[$definition['id']][$element][$targetEntityBundle]['base_data'] = [
'projectId' => $this->mapping
->getGathercontentProjectId(),
'templateId' => $this->mapping
->getGathercontentTemplateId(),
'entityType' => $targetFieldInfo
->getTargetEntityTypeId(),
'contentType' => $targetEntityBundle,
];
$this->collectedReferences[$definition['id']][$element][$targetEntityBundle]['reference_data'][] = $elementId;
break;
default:
$this
->setTextFieldDefinition($definition, $element, $elementId, $isMultiple);
break;
}
if (isset($definition['process'][$element]) && $definition['langcode'] != $this->siteDefaultLangCode && $definition['langcode'] != 'und' && $isTranslatable) {
$definition['process'][$element]['language'] = $definition['langcode'];
}
}