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
f201570b
"git@git.drupal.org:issue/automatic_updates-3406010.git" did not exist on "192e70df296dad68e12961dfd2b35e7e7d007fbb"
Commit
f201570b
authored
8 years ago
by
Mike Ryan
Committed by
Mike Ryan
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2765543
by mikeryan: Deprecate "stub" language in entity_generate
parent
bb296e33
No related branches found
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/EntityGenerate.php
+18
-23
18 additions, 23 deletions
src/Plugin/migrate/process/EntityGenerate.php
with
18 additions
and
23 deletions
src/Plugin/migrate/process/EntityGenerate.php
+
18
−
23
View file @
f201570b
<?php
<?php
/**
* @file
* Contains Drupal\migrate_plus\Plugin\migrate\process\EntityGenerate.
*/
namespace
Drupal\migrate_plus\Plugin\migrate\process
;
namespace
Drupal\migrate_plus\Plugin\migrate\process
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Row
;
use
Drupal\migrate\Row
;
/**
/**
* This plugin generates entit
y stubs
.
* This plugin generates entit
ies within the process plugin
.
*
*
* @MigrateProcessPlugin(
* @MigrateProcessPlugin(
* id = "entity_generate"
* id = "entity_generate"
...
@@ -19,9 +14,9 @@ use Drupal\migrate\Row;
...
@@ -19,9 +14,9 @@ use Drupal\migrate\Row;
*
*
* @see EntityLookup
* @see EntityLookup
*
*
* All the configuration from the lookup plugin applies here. In it
'
s most
* All the configuration from the lookup plugin applies here. In its most
* simple form, this plugin needs no configuration. If there are fields on the
* simple form, this plugin needs no configuration. If there are fields on the
*
stub
entity that are required or need some default value, that can be
*
generated
entity that are required or need some default value, that can be
* provided via a default_values configuration option.
* provided via a default_values configuration option.
*
*
* Example usage with default_values configuration:
* Example usage with default_values configuration:
...
@@ -36,8 +31,8 @@ use Drupal\migrate\Row;
...
@@ -36,8 +31,8 @@ use Drupal\migrate\Row;
* plugin: entity_generate
* plugin: entity_generate
* source: tags
* source: tags
* default_values:
* default_values:
* description:
Stub
description
* description:
Default
description
* field_long_description:
Stub
long description
* field_long_description:
Default
long description
* @endcode
* @endcode
*/
*/
class
EntityGenerate
extends
EntityLookup
{
class
EntityGenerate
extends
EntityLookup
{
...
@@ -46,7 +41,7 @@ class EntityGenerate extends EntityLookup {
...
@@ -46,7 +41,7 @@ class EntityGenerate extends EntityLookup {
* {@inheritdoc}
* {@inheritdoc}
*/
*/
public
function
transform
(
$value
,
MigrateExecutableInterface
$migrateExecutable
,
Row
$row
,
$destinationProperty
)
{
public
function
transform
(
$value
,
MigrateExecutableInterface
$migrateExecutable
,
Row
$row
,
$destinationProperty
)
{
// Creates a
stub
entity if
one
doesn't exist.
// Creates a
n
entity if
the lookup determines it
doesn't exist.
if
(
!
(
$result
=
parent
::
transform
(
$value
,
$migrateExecutable
,
$row
,
$destinationProperty
)))
{
if
(
!
(
$result
=
parent
::
transform
(
$value
,
$migrateExecutable
,
$row
,
$destinationProperty
)))
{
$result
=
$this
->
generateEntity
(
$value
);
$result
=
$this
->
generateEntity
(
$value
);
}
}
...
@@ -55,19 +50,19 @@ class EntityGenerate extends EntityLookup {
...
@@ -55,19 +50,19 @@ class EntityGenerate extends EntityLookup {
}
}
/**
/**
* Generates
stub
entity for a given value.
* Generates
an
entity for a given value.
*
*
* @param string $value
* @param string $value
* Value to use in creation of
stub
entity.
* Value to use in creation of
the
entity.
*
*
* @return int|string
* @return int|string
* The entity id of the generated entity.
* The entity id of the generated entity.
*/
*/
protected
function
generateEntity
(
$value
)
{
protected
function
generateEntity
(
$value
)
{
if
(
!
empty
(
$value
))
{
if
(
!
empty
(
$value
))
{
$entity
=
$this
->
entityManager
$entity
=
$this
->
entityManager
->
getStorage
(
$this
->
lookupEntityType
)
->
getStorage
(
$this
->
lookupEntityType
)
->
create
(
$this
->
stub
(
$value
));
->
create
(
$this
->
entity
(
$value
));
$entity
->
save
();
$entity
->
save
();
return
$entity
->
id
();
return
$entity
->
id
();
...
@@ -75,32 +70,32 @@ class EntityGenerate extends EntityLookup {
...
@@ -75,32 +70,32 @@ class EntityGenerate extends EntityLookup {
}
}
/**
/**
* Fabricate a
stub
entity.
* Fabricate a
n
entity.
*
*
* This is intended to be extended by implementing classes to provide for more
* This is intended to be extended by implementing classes to provide for more
* dynamic default values, rather than just static ones.
* dynamic default values, rather than just static ones.
*
*
* @param $value
* @param $value
*
V
alue to use in creation of
stub
entity.
*
Primary v
alue to use in creation of
the
entity.
*
*
* @return array
* @return array
*
The stub entit
y.
*
Entity value arra
y.
*/
*/
protected
function
stub
(
$value
)
{
protected
function
entity
(
$value
)
{
$
stub
=
[
$this
->
lookupValueKey
=>
$value
];
$
entity_values
=
[
$this
->
lookupValueKey
=>
$value
];
if
(
$this
->
lookupBundleKey
)
{
if
(
$this
->
lookupBundleKey
)
{
$
stub
[
$this
->
lookupBundleKey
]
=
$this
->
lookupBundle
;
$
entity_values
[
$this
->
lookupBundleKey
]
=
$this
->
lookupBundle
;
}
}
// Gather any static default values for properties/fields.
// Gather any static default values for properties/fields.
if
(
isset
(
$this
->
configuration
[
'default_values'
])
&&
is_array
(
$this
->
configuration
[
'default_values'
]))
{
if
(
isset
(
$this
->
configuration
[
'default_values'
])
&&
is_array
(
$this
->
configuration
[
'default_values'
]))
{
foreach
(
$this
->
configuration
[
'default_values'
]
as
$key
=>
$value
)
{
foreach
(
$this
->
configuration
[
'default_values'
]
as
$key
=>
$value
)
{
$
stub
[
$key
]
=
$value
;
$
entity_values
[
$key
]
=
$value
;
}
}
}
}
return
$
stub
;
return
$
entity_values
;
}
}
}
}
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