Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migrate_plus
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
migrate_plus
Commits
70315894
Commit
70315894
authored
8 years ago
by
Mike Ryan
Committed by
Mike Ryan
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2765733
by mikeryan: entity_lookup should support file/image destination fields
parent
ad60821f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/migrate/process/EntityLookup.php
+30
-20
30 additions, 20 deletions
src/Plugin/migrate/process/EntityLookup.php
with
30 additions
and
20 deletions
src/Plugin/migrate/process/EntityLookup.php
+
30
−
20
View file @
70315894
...
...
@@ -150,27 +150,37 @@ class EntityLookup extends ProcessPluginBase implements ContainerFactoryPluginIn
if
(
!
empty
(
$this
->
migration
->
getProcess
()[
$this
->
destinationBundleKey
][
0
][
'default_value'
]))
{
$destinationEntityBundle
=
$this
->
migration
->
getProcess
()[
$this
->
destinationBundleKey
][
0
][
'default_value'
];
$fieldConfig
=
$this
->
entityManager
->
getFieldDefinitions
(
$this
->
destinationEntityType
,
$destinationEntityBundle
)[
$destinationProperty
]
->
getConfig
(
$destinationEntityBundle
);
if
(
$fieldConfig
->
getType
()
!=
'entity_reference'
)
{
throw
new
MigrateException
(
'The entity_lookup plugin found no entity reference field.'
);
switch
(
$fieldConfig
->
getType
())
{
case
'entity_reference'
:
if
(
empty
(
$this
->
lookupBundle
))
{
$handlerSettings
=
$fieldConfig
->
getSetting
(
'handler_settings'
);
$bundles
=
array_filter
((
array
)
$handlerSettings
[
'target_bundles'
]);
if
(
count
(
$bundles
)
==
1
)
{
$this
->
lookupBundle
=
reset
(
$bundles
);
}
// This was added in 8.1.x is not supported in 8.0.x.
elseif
(
!
empty
(
$handlerSettings
[
'auto_create'
])
&&
!
empty
(
$handlerSettings
[
'auto_create_bundle'
]))
{
$this
->
lookupBundle
=
reset
(
$handlerSettings
[
'auto_create_bundle'
]);
}
}
// Make an assumption that if the selection handler can target more than
// one type of entity that we will use the first entity type.
$this
->
lookupEntityType
=
$this
->
lookupEntityType
?:
reset
(
$this
->
selectionPluginManager
->
createInstance
(
$fieldConfig
->
getSetting
(
'handler'
))
->
getPluginDefinition
()[
'entity_types'
]);
$this
->
lookupValueKey
=
$this
->
lookupValueKey
?:
$this
->
entityManager
->
getDefinition
(
$this
->
lookupEntityType
)
->
getKey
(
'label'
);
$this
->
lookupBundleKey
=
$this
->
lookupBundleKey
?:
$this
->
entityManager
->
getDefinition
(
$this
->
lookupEntityType
)
->
getKey
(
'bundle'
);
break
;
case
'file'
:
case
'image'
:
$this
->
lookupEntityType
=
'file'
;
$this
->
lookupValueKey
=
$this
->
lookupValueKey
?:
'uri'
;
break
;
default
:
throw
new
MigrateException
(
'Destination field type '
.
$fieldConfig
->
getType
()
.
'is not a recognized reference type.'
);
}
if
(
empty
(
$this
->
lookupBundle
))
{
$handlerSettings
=
$fieldConfig
->
getSetting
(
'handler_settings'
);
$bundles
=
array_filter
((
array
)
$handlerSettings
[
'target_bundles'
]);
if
(
count
(
$bundles
)
==
1
)
{
$this
->
lookupBundle
=
reset
(
$bundles
);
}
// This was added in 8.1.x is not supported in 8.0.x.
elseif
(
!
empty
(
$handlerSettings
[
'auto_create'
])
&&
!
empty
(
$handlerSettings
[
'auto_create_bundle'
]))
{
$this
->
lookupBundle
=
reset
(
$handlerSettings
[
'auto_create_bundle'
]);
}
}
// Make an assumption that if the selection handler can target more than
// one type of entity that we will use the first entity type.
$this
->
lookupEntityType
=
$this
->
lookupEntityType
?:
reset
(
$this
->
selectionPluginManager
->
createInstance
(
$fieldConfig
->
getSetting
(
'handler'
))
->
getPluginDefinition
()[
'entity_types'
]);
$this
->
lookupValueKey
=
$this
->
lookupValueKey
?:
$this
->
entityManager
->
getDefinition
(
$this
->
lookupEntityType
)
->
getKey
(
'label'
);
$this
->
lookupBundleKey
=
$this
->
lookupBundleKey
?:
$this
->
entityManager
->
getDefinition
(
$this
->
lookupEntityType
)
->
getKey
(
'bundle'
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment