Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
migrate_scanner
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_scanner
Merge requests
!1
Issue
#3214186
: Scan for snippets of process plugins
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Issue
#3214186
: Scan for snippets of process plugins
issue/migrate_scanner-3214186:3214186-scan-for-snippets
into
1.0.x
Overview
0
Commits
2
Pipelines
0
Changes
2
Open
Benji Fisher
requested to merge
issue/migrate_scanner-3214186:3214186-scan-for-snippets
into
1.0.x
4 years ago
Overview
0
Commits
2
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
1.0.x
1.0.x (base)
and
latest version
latest version
d42efbe8
2 commits,
4 years ago
2 files
+
136
−
1
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
src/Plugin/migrate/process/Snippet.php
0 → 100644
+
135
−
0
Options
<?php
namespace
Drupal\migrate_scanner\Plugin\migrate\process
;
use
Drupal\Core\Extension\ModuleHandlerInterface
;
use
Drupal\Core\Plugin\ContainerFactoryPluginInterface
;
use
Drupal\migrate\MigrateException
;
use
Drupal\migrate\MigrateExecutableInterface
;
use
Drupal\migrate\Plugin\MigratePluginManagerInterface
;
use
Drupal\migrate\ProcessPluginBase
;
use
Drupal\migrate\Row
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\Yaml\Yaml
;
/**
* Applies process plugins described in YAML snippets.
*
* Available configuration keys:
* - module: the module providing the snippet
* - path: path of the YAML file, relative to module/migrations/process and
* without the .yml extension.
*
* Example:
*
* Suppose the file mymodule/migrations/process/clean_whitespace.yml contains
* the following:
*
* @code
* -
* plugin: callback
* callable: htmlentities
* -
* plugin: str_replace
* search:
* - ' '
* - ' '
* replace: ' '
* -
* plugin: str_replace
* regex: true
* search: '@\s+@'
* replace: ' '
* -
* plugin: callback
* callable: trim
* @endcode
*
* Then that process pipeline can be used as follows:
*
* @code
* process:
* field_formatted_text:
* plugin: snippet
* module: mymodule
* path: clean_whitespace
* source: html_string
* @endcode
*
* @MigrateProcessPlugin(
* id = "snippet"
* )
*/
class
Snippet
extends
ProcessPluginBase
implements
ContainerFactoryPluginInterface
{
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected
$moduleHandler
;
/**
* The process pipeline.
*
* @var Drupal\migrate\Plugin\MigrateProcessInterface[]
*/
protected
$pipeline
=
[];
/**
* Constructs a download process plugin.
*
* @param array $configuration
* The plugin configuration.
* @param string $plugin_id
* The plugin ID.
* @param array $plugin_definition
* The plugin definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\migrate\Plugin\MigratePluginManagerInterface $plugin_manager
* The process plugin manager.
*/
public
function
__construct
(
array
$configuration
,
$plugin_id
,
array
$plugin_definition
,
ModuleHandlerInterface
$module_handler
,
MigratePluginManagerInterface
$plugin_manager
)
{
parent
::
__construct
(
$configuration
,
$plugin_id
,
$plugin_definition
);
$this
->
moduleHandler
=
$module_handler
;
// @todo Add error checking: the module is enabled, the file exists, the
// YAML is valid.
$snippet_file
=
implode
(
'/'
,
[
$this
->
moduleHandler
->
getModule
(
$this
->
configuration
[
'module'
])
->
getPath
(),
'migrations/process'
,
$this
->
configuration
[
'path'
],
])
.
'.yml'
;
$steps
=
Yaml
::
parse
(
file_get_contents
(
$snippet_file
));
foreach
(
$steps
as
$step_configuration
)
{
$step_id
=
$step_configuration
[
'plugin'
];
unset
(
$step_configuration
[
'plugin'
]);
$this
->
pipeline
[]
=
$plugin_manager
->
createInstance
(
$step_id
,
$step_configuration
);
}
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
,
array
$configuration
,
$plugin_id
,
$plugin_definition
)
{
return
new
static
(
$configuration
,
$plugin_id
,
$plugin_definition
,
$container
->
get
(
'module_handler'
),
$container
->
get
(
'plugin.manager.migrate.process'
)
);
}
/**
* {@inheritdoc}
*/
public
function
transform
(
$value
,
MigrateExecutableInterface
$migrate_executable
,
Row
$row
,
$destination_property
)
{
foreach
(
$this
->
pipeline
as
$step
)
{
$value
=
$step
->
transform
(
$value
,
$migrate_executable
,
$row
,
$destination_property
);
}
return
$value
;
}
}
Loading