clean install

This commit is contained in:
matze committed 2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 files changed
+3555714

No files matched your search

@@ -0,0 +1,58 @@
INTRODUCTION
------------
The migrate_example_advanced module demonstrates some techniques for Drupal 8+
migrations beyond the basics in migrate_example. It includes a group of
migrations with a wine theme.
SETUP
-----
To demonstrate XML migrations as realistically as possible, the setup module
provides the source data as REST services. So the migrations' references to
these services can be set up accurately, if you install migrate_example_advanced
via drush be sure to use the --uri parameter, e.g.
drush en -y migrate_example_advanced --uri=http://d8.local:8083/
THE WINE SITE
-------------
In this scenario, we have a wine aficionado site which stores data in SQL tables
as well is pulling in additional data from XML services.
To make the example as simple as to run as possible, the SQL data is placed in
tables directly in your Drupal database - in most real-world scenarios, your
source data will be in an external database. The migrate_example_advanced_setup
submodule creates and populates these tables, as well as configuring your Drupal
8 site (creating node types, vocabularies, fields, etc.) to receive the data,
and providing service endpoints for XML data.
STRUCTURE
---------
As with most custom migrations, there are two primary components to this
example:
1. Migration configuration, in the config/install directory. These YAML files
describe the migration process and provide the mappings from the source data
to Drupal's destination entities.
2. Source plugins, in src/Plugin/migrate/source. These are referenced from the
configuration files, and provide the source data to the migration processing
pipeline, as well as manipulating that data where necessary to put it into
a canonical form for migrations.
UNDERSTANDING THE MIGRATIONS
----------------------------
Basic techniques demonstrated in the migrate_example module are not rehashed
here - it is expected that if you are learning Drupal 8+ migration, you will
study and understand those examples first, and use migrate_example_advanced to
learn about specific techniques beyond those basics. This example doesn't have
the narrative form of migrate_example - it's more of a grab-bag demonstrating
varous features, and is more of a reference for, say, copying the code to set
up an XML migration. An index of things demonstrated by this module:
Multiple vocabularies populated in one migration
------------------------------------------------
See migrate_plus.migration.wine_terms.yml.
Importing from XML services
---------------------------
See migrate_plus.migration.wine_role_xml.yml.
@@ -0,0 +1,56 @@
# This migration demonstrates importing from SOAP/WSDL.
id: weather_soap
label: SOAP service providing weather.
migration_group: wine
migration_tags:
- advanced example
source:
# We use the SOAP parser source plugin.
plugin: url
data_fetcher_plugin: http # Ignored - SoapClient does the fetching.
data_parser_plugin: soap
# URL of a WSDL endpoint.
urls:
- http://www.webservicex.net/globalweather.asmx?WSDL
# The function to call on the service, and the parameters to pass. See
# http://www.webservicex.net/New/Home/ServiceDetail/56 for the XML structure
# of this feed - how CountryName is passed within the GetCitiesByCountry
# XML element.
function: GetCitiesByCountry
parameters:
CountryName: Spain
# Responses may be returned as an XML string, an object, or an array - specify
# the type of response here.
response_type: xml
# Looking at the XML response at http://www.webservicex.net/globalweather.asmx/GetCitiesByCountry,
# we see that the data items we want are within <NewDataSet><Table>.
item_selector: /NewDataSet/Table
# For each field, 'name' is the source property name to be used in the process
# steps below, 'label' is optional (to document the property), and selector
# is an xpath (-like, for array and object returns) string relative to the
# item_selector for retrieving that data value.
fields:
-
name: Country
label: Country
selector: Country
-
name: City
label: City
selector: City
# 'ids' tells us what source property ('City') holds the unique identifying
# value for each imported item, and what schema type to use to hold that
# value in the migration map an message tables.
ids:
City:
type: string
process:
vid:
plugin: default_value
default_value: migrate_example_wine_varieties
name: City
destination:
plugin: entity:taxonomy_term
migration_dependencies:
required: {}
optional: {}
@@ -0,0 +1,58 @@
# This migration demonstrates importing from a monolithic JSON file.
id: wine_role_json
label: JSON feed of roles (positions)
migration_group: wine
migration_tags:
- advanced example
source:
# We use the JSON source plugin.
plugin: url
data_fetcher_plugin: http
data_parser_plugin: json
# The data_parser normally limits the fields passed on to the source plugin
# to fields configured to be used as part of the migration. To support more
# dynamic migrations, the JSON data parser supports including the original
# data for the current row. Simply include the 'include_raw_data' flag set
# to `true` to enable this. This option is disabled by default to minimize
# memory footprint for migrations that do not need this capability.
# include_raw_data: true
# Normally, this is one or more fully-qualified URLs or file paths. Because
# we can't hardcode your local URL, we provide a relative path here which
# hook_install() will rewrite to a full URL for the current site.
urls:
- /migrate_example_advanced_position?_format=json
# An xpath-like selector corresponding to the items to be imported.
item_selector: position
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
# we provide a label (optional - this is for display in migration tools) and
# an xpath for retrieving that value. It's important to note that this xpath
# is relative to the elements retrieved by item_selector.
fields:
-
name: machine_name
label: 'Unique position identifier'
selector: sourceid
-
name: friendly_name
label: 'Position name'
selector: name
# Under 'ids', we identify source fields populated above which will uniquely
# identify each imported item. The 'type' makes sure the migration map table
# uses the proper schema type for stored the IDs.
ids:
machine_name:
type: string
process:
# Note that the source field names here (machine_name and friendly_name) were
# defined by the 'fields' configuration for the source plugin above.
id: machine_name
label: friendly_name
destination:
plugin: entity:user_role
migration_dependencies: {}
dependencies:
enforced:
module:
- migrate_example_advanced
@@ -0,0 +1,54 @@
# This migration demonstrates importing from a monolithic XML file.
id: wine_role_xml
label: XML feed of roles (positions)
migration_group: wine
migration_tags:
- advanced example
source:
# We use the XML data parser plugin.
plugin: url
data_fetcher_plugin: http
data_parser_plugin: xml
# Normally, this is one or more fully-qualified URLs or file paths. Because
# we can't hardcode your local URL, we provide a relative path here which
# hook_install() will rewrite to a full URL for the current site.
urls:
- /migrate_example_advanced_position?_format=xml
# Visit the URL above (relative to your site root) and look at it. You can see
# that <response> is the outer element, and each item we want to import is a
# <position> element. The item_xpath value is the xpath to use to query the
# desired elements.
item_selector: /response/position
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
# we provide a label (optional - this is for display in migration tools) and
# an xpath for retrieving that value. It's important to note that this xpath
# is relative to the elements retrieved by item_xpath.
fields:
-
name: machine_name
label: 'Unique position identifier'
selector: sourceid
-
name: friendly_name
label: 'Position name'
selector: name
# Under 'ids', we identify source fields populated above which will uniquely
# identify each imported item. The 'type' makes sure the migration map table
# uses the proper schema type for stored the IDs.
ids:
machine_name:
type: string
process:
# Note that the source field names here (machine_name and friendly_name) were
# defined by the 'fields' configuration for the source plugin above.
id: machine_name
label: friendly_name
destination:
plugin: entity:user_role
migration_dependencies: {}
dependencies:
enforced:
module:
- migrate_example_advanced
@@ -0,0 +1,39 @@
id: wine_terms
label: Migrate all categories into Drupal taxonomy terms
migration_group: wine
migration_tags:
- advanced example
source:
plugin: wine_term
destination:
plugin: entity:taxonomy_term
process:
name: name
description: details
# Usually, one wants to have a separate migration for each entity_type/bundle
# combination - e.g., separate migrations for articles and blog posts, as
# opposed to a single monolithic node migration. This affords maximum
# control - the ability to import just one bundle at a time, and most
# importantly to have distinct field mappings (because different node types
# usually have different fields). In this case, though, because all of the
# vocabularies we're importing come from a common table, and on the Drupal
# side there are no distinct custom fields, we are able to import them all in
# one migration. The static_map tells the migration in which vocabulary to
# place each term, based on the incoming 'type' column.
vid:
plugin: static_map
source: type
map:
best_with: migrate_example_wine_best_with
region: migrate_example_wine_regions
variety: migrate_example_wine_varieties
parent:
plugin: migration_lookup
migration: wine_terms
source: category_parent
weight: ordering
migration_dependencies: {}
dependencies:
enforced:
module:
- migrate_example_advanced
@@ -0,0 +1,74 @@
# This migration demonstrates importing from multiple XML files.
id: wine_variety_multi_xml
label: XML feed of varieties
migration_group: wine
migration_tags:
- advanced example
source:
# We use the XML source plugin.
plugin: url
data_fetcher_plugin: http
data_parser_plugin: xml
# Guzzle request options can be added.
request_options:
allow_redirects: false
# Normally, this is one or more fully-qualified URLs or file paths. Because
# we can't hardcode your local URL, we provide a relative path here which
# hook_install() will rewrite to a full URL for the current site.
urls:
- /migrate_example_advanced_variety_multiple/red?_format=xml
- /migrate_example_advanced_variety_multiple/white?_format=xml
# Visit the URL above (relative to your site root) and look at it. You can see
# that <response> is the outer element, and each item we want to import is a
# <position> element. The item_xpath value is the xpath to use to query the
# desired elements.
item_selector: /response/variety
# Under 'fields', we list the data items to be imported. The first level keys
# are the source field names we want to populate (the names to be used as
# sources in the process configuration below). For each field we're importing,
# we provide a label (optional - this is for display in migration tools) and
# an xpath for retrieving that value. It's important to note that this xpath
# is relative to the elements retrieved by item_xpath.
fields:
-
name: category_name
label: Name
selector: name
-
name: category_details
label: Details
selector: details
-
name: category_parent
label: 'Unique position identifier'
selector: parent
-
name: category_attributes
label: 'List of variety attributes'
selector: attributes
# Under 'ids', we identify source fields populated above which will uniquely
# identify each imported item. The 'type' makes sure the migration map table
# uses the proper schema type for stored the IDs.
ids:
category_name:
type: string
process:
vid:
plugin: default_value
default_value: migrate_example_wine_varieties
name: category_name
description: category_details
parent:
plugin: migration_lookup
migration: wine_terms
source: category_parent
field_variety_attributes: category_attributes
destination:
plugin: entity:taxonomy_term
migration_dependencies:
required:
- wine_terms
dependencies:
enforced:
module:
- migrate_example_advanced
@@ -0,0 +1,11 @@
id: wine
label: Wine Imports
description: A few wine-related imports, demonstrating some more advanced migration techniques.
source_type: Custom tables and XML
shared_configuration:
source:
key: default
dependencies:
enforced:
module:
- migrate_example_advanced
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<producer>
<name>Lolonis Winery</name>
<description>Makers of Ladybug Red</description>
<authorid>3</authorid>
<region>Redwood Valley</region>
</producer>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<pr:producer xmlns:pr="http://www.wine.org/wine-producers">
<pr:name>Château Latour</pr:name>
<pr:description>Makers of grand vin Chateau Latour, Les Forts de Latour and Pauillac</pr:description>
<pr:authorid>3</pr:authorid>
<pr:region>Bordeaux</pr:region>
</pr:producer>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<content>
<sourceid>0001</sourceid>
</content>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<wn:content xmlns:wn="http://www.wine.org/wine">
<wn:sourceid>0002</wn:sourceid>
</wn:content>
@@ -0,0 +1,14 @@
type: module
name: Migrate Example (Advanced)
description: 'Specialized examples of Drupal 8+ migration.'
package: Examples
core_version_requirement: '>=9.1'
dependencies:
- drupal:migrate
- migrate_plus:migrate_example_advanced_setup
- migrate_plus:migrate_plus
# Information added by Drupal.org packaging script on 2024-11-20
version: '6.0.5'
project: 'migrate_plus'
datestamp: 1732124626
@@ -0,0 +1,60 @@
<?php
declare(strict_types = 1);
/**
* @file
* Install, update and uninstall functions for migrate_example_advanced module.
*/
use Drupal\migrate_plus\Entity\Migration;
/**
* Implements hook_install().
*
* We need the urls to be absolute for the XML source plugin to read them, but
* the static configuration files on disk can't know the server and port to
* use. So, in the .yml files we provide the REST resources relative to the
* site root and here rewrite them to fully-qualified paths.
*/
function migrate_example_advanced_install(): void {
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_xml_migration */
$wine_role_xml_migration = Migration::load('wine_role_xml');
if ($wine_role_xml_migration) {
$source = $wine_role_xml_migration->get('source');
$request = \Drupal::request();
$urls = [];
foreach ($source['urls'] as $url) {
$urls[] = 'http://' . $request->getHttpHost() . $url;
}
$source['urls'] = $urls;
$wine_role_xml_migration->set('source', $source);
$wine_role_xml_migration->save();
}
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_role_json_migration */
$wine_role_json_migration = Migration::load('wine_role_json');
if ($wine_role_json_migration) {
$source = $wine_role_json_migration->get('source');
$request = \Drupal::request();
$urls = [];
foreach ($source['urls'] as $url) {
$urls[] = 'http://' . $request->getHttpHost() . $url;
}
$source['urls'] = $urls;
$wine_role_json_migration->set('source', $source);
$wine_role_json_migration->save();
}
/** @var \Drupal\migrate_plus\Entity\MigrationInterface $wine_variety_multi_xml_migration */
$wine_variety_multi_xml_migration = Migration::load('wine_variety_multi_xml');
if ($wine_variety_multi_xml_migration) {
$source = $wine_variety_multi_xml_migration->get('source');
$request = \Drupal::request();
$urls = [];
foreach ($source['urls'] as $url) {
$urls[] = 'http://' . $request->getHttpHost() . $url;
}
$source['urls'] = $urls;
$wine_variety_multi_xml_migration->set('source', $source);
$wine_variety_multi_xml_migration->save();
}
}
@@ -0,0 +1,10 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
id: migrate_example_advanced_comment
label: 'Node comments'
target_entity_type_id: node
description: ''
@@ -0,0 +1,30 @@
langcode: en
status: true
dependencies:
config:
- comment.type.migrate_example_advanced_comment
- field.field.comment.migrate_example_advanced_comment.comment_body
module:
- text
id: comment.migrate_example_advanced_comment.default
targetEntityType: comment
bundle: migrate_example_advanced_comment
mode: default
content:
author:
weight: -2
comment_body:
type: text_textarea
weight: 11
settings:
rows: 5
placeholder: ''
third_party_settings: { }
subject:
type: string_textfield
weight: 10
settings:
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
@@ -0,0 +1,71 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.migrate_example_producer.body
- field.field.node.migrate_example_producer.field_migrate_example_wine_regio
- node.type.migrate_example_producer
module:
- path
- text
id: node.migrate_example_producer.default
targetEntityType: node
bundle: migrate_example_producer
mode: default
content:
body:
type: text_textarea_with_summary
weight: 31
settings:
rows: 9
summary_rows: 3
placeholder: ''
third_party_settings: { }
created:
type: datetime_timestamp
weight: 10
settings: { }
third_party_settings: { }
field_migrate_example_wine_regio:
weight: 32
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
type: entity_reference_autocomplete
path:
type: path
weight: 30
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 16
third_party_settings: { }
title:
type: string_textfield
weight: -5
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
@@ -0,0 +1,121 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.migrate_example_wine.body
- field.field.node.migrate_example_wine.field_migrate_example_comments
- field.field.node.migrate_example_wine.field_migrate_example_adv_image
- field.field.node.migrate_example_wine.field_migrate_example_top_vintag
- field.field.node.migrate_example_wine.field_migrate_example_wine_best
- field.field.node.migrate_example_wine.field_migrate_example_wine_ratin
- field.field.node.migrate_example_wine.field_migrate_example_wine_regio
- field.field.node.migrate_example_wine.field_migrate_example_wine_var
- node.type.migrate_example_wine
module:
- comment
- image
- path
- text
id: node.migrate_example_wine.default
targetEntityType: node
bundle: migrate_example_wine
mode: default
content:
body:
type: text_textarea_with_summary
weight: 31
settings:
rows: 9
summary_rows: 3
placeholder: ''
third_party_settings: { }
created:
type: datetime_timestamp
weight: 10
settings: { }
third_party_settings: { }
field_migrate_example_comments:
weight: 38
settings: { }
third_party_settings: { }
type: comment_default
field_migrate_example_adv_image:
weight: 35
settings:
progress_indicator: throbber
preview_image_style: thumbnail
third_party_settings: { }
type: image_image
field_migrate_example_top_vintag:
weight: 37
settings:
placeholder: ''
third_party_settings: { }
type: number
field_migrate_example_wine_best:
weight: 34
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
type: entity_reference_autocomplete_tags
field_migrate_example_wine_ratin:
weight: 36
settings:
placeholder: ''
third_party_settings: { }
type: number
field_migrate_example_wine_regio:
weight: 33
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
type: entity_reference_autocomplete
field_migrate_example_wine_var:
weight: 32
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
type: entity_reference_autocomplete
path:
type: path
weight: 30
settings: { }
third_party_settings: { }
promote:
type: boolean_checkbox
settings:
display_label: true
weight: 15
third_party_settings: { }
sticky:
type: boolean_checkbox
settings:
display_label: true
weight: 16
third_party_settings: { }
title:
type: string_textfield
weight: -5
settings:
size: 60
placeholder: ''
third_party_settings: { }
uid:
type: entity_reference_autocomplete
weight: 5
settings:
match_operator: CONTAINS
match_limit: 10
size: 60
placeholder: ''
third_party_settings: { }
hidden: { }
@@ -0,0 +1,41 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.migrate_example_wine_varieties.field_variety_attributes
- taxonomy.vocabulary.migrate_example_wine_varieties
module:
- path
- text
id: taxonomy_term.migrate_example_wine_varieties.default
targetEntityType: taxonomy_term
bundle: migrate_example_wine_varieties
mode: default
content:
description:
type: text_textarea
weight: 1
settings:
placeholder: ''
rows: 5
third_party_settings: { }
field_variety_attributes:
type: string_textfield
weight: 3
settings:
size: 60
placeholder: ''
third_party_settings: { }
name:
type: string_textfield
weight: 0
settings:
size: 60
placeholder: ''
third_party_settings: { }
path:
type: path
weight: 2
settings: { }
third_party_settings: { }
hidden: { }
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- comment.type.migrate_example_advanced_comment
- field.field.comment.migrate_example_advanced_comment.comment_body
module:
- text
id: comment.migrate_example_advanced_comment.default
targetEntityType: comment
bundle: migrate_example_advanced_comment
mode: default
content:
comment_body:
label: hidden
type: text_default
weight: 0
settings: { }
third_party_settings: { }
links:
weight: 100
hidden: { }
@@ -0,0 +1,33 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.migrate_example_producer.body
- field.field.node.migrate_example_producer.field_migrate_example_wine_regio
- node.type.migrate_example_producer
module:
- text
- user
id: node.migrate_example_producer.default
targetEntityType: node
bundle: migrate_example_producer
mode: default
content:
body:
label: hidden
type: text_default
weight: 101
settings: { }
third_party_settings: { }
field_migrate_example_wine_regio:
weight: 102
label: inline
settings:
link: true
third_party_settings: { }
type: entity_reference_label
links:
weight: 100
settings: { }
third_party_settings: { }
hidden: { }
@@ -0,0 +1,27 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.migrate_example_producer.body
- field.field.node.migrate_example_producer.field_migrate_example_wine_regio
- node.type.migrate_example_producer
module:
- text
- user
id: node.migrate_example_producer.teaser
targetEntityType: node
bundle: migrate_example_producer
mode: teaser
content:
body:
label: hidden
type: text_summary_or_trimmed
weight: 101
settings:
trim_length: 600
third_party_settings: { }
links:
weight: 100
hidden:
field_migrate_example_wine_regio: true
@@ -0,0 +1,88 @@
langcode: en
status: true
dependencies:
config:
- field.field.node.migrate_example_wine.body
- field.field.node.migrate_example_wine.field_migrate_example_comments
- field.field.node.migrate_example_wine.field_migrate_example_adv_image
- field.field.node.migrate_example_wine.field_migrate_example_top_vintag
- field.field.node.migrate_example_wine.field_migrate_example_wine_best
- field.field.node.migrate_example_wine.field_migrate_example_wine_ratin
- field.field.node.migrate_example_wine.field_migrate_example_wine_regio
- field.field.node.migrate_example_wine.field_migrate_example_wine_var
- node.type.migrate_example_wine
module:
- comment
- image
- text
- user
id: node.migrate_example_wine.default
targetEntityType: node
bundle: migrate_example_wine
mode: default
content:
body:
label: hidden
type: text_default
weight: 101
settings: { }
third_party_settings: { }
field_migrate_example_comments:
weight: 108
label: hidden
settings:
pager_id: 0
third_party_settings: { }
type: comment_default
field_migrate_example_adv_image:
weight: 105
label: hidden
settings:
image_style: ''
image_link: ''
third_party_settings: { }
type: image
field_migrate_example_top_vintag:
weight: 107
label: inline
settings:
thousand_separator: ''
prefix_suffix: true
third_party_settings: { }
type: number_integer
field_migrate_example_wine_best:
weight: 104
label: inline
settings:
link: true
third_party_settings: { }
type: entity_reference_label
field_migrate_example_wine_ratin:
weight: 106
label: inline
settings:
thousand_separator: ''
decimal_separator: .
scale: 2
prefix_suffix: true
third_party_settings: { }
type: number_decimal
field_migrate_example_wine_regio:
weight: 103
label: inline
settings:
link: true
third_party_settings: { }
type: entity_reference_label
field_migrate_example_wine_var:
weight: 102
label: inline
settings:
link: true
third_party_settings: { }
type: entity_reference_label
links:
weight: 100
settings: { }
third_party_settings: { }
hidden: { }
@@ -0,0 +1,39 @@
langcode: en
status: true
dependencies:
config:
- core.entity_view_mode.node.teaser
- field.field.node.migrate_example_wine.body
- field.field.node.migrate_example_wine.field_migrate_example_comments
- field.field.node.migrate_example_wine.field_migrate_example_adv_image
- field.field.node.migrate_example_wine.field_migrate_example_top_vintag
- field.field.node.migrate_example_wine.field_migrate_example_wine_best
- field.field.node.migrate_example_wine.field_migrate_example_wine_ratin
- field.field.node.migrate_example_wine.field_migrate_example_wine_regio
- field.field.node.migrate_example_wine.field_migrate_example_wine_var
- node.type.migrate_example_wine
module:
- text
- user
id: node.migrate_example_wine.teaser
targetEntityType: node
bundle: migrate_example_wine
mode: teaser
content:
body:
label: hidden
type: text_summary_or_trimmed
weight: 101
settings:
trim_length: 600
third_party_settings: { }
links:
weight: 100
hidden:
field_migrate_example_comments: true
field_migrate_example_adv_image: true
field_migrate_example_top_vintag: true
field_migrate_example_wine_best: true
field_migrate_example_wine_ratin: true
field_migrate_example_wine_regio: true
field_migrate_example_wine_var: true
@@ -0,0 +1,27 @@
langcode: en
status: true
dependencies:
config:
- field.field.taxonomy_term.migrate_example_wine_varieties.field_variety_attributes
- taxonomy.vocabulary.migrate_example_wine_varieties
module:
- text
id: taxonomy_term.migrate_example_wine_varieties.default
targetEntityType: taxonomy_term
bundle: migrate_example_wine_varieties
mode: default
content:
description:
label: hidden
type: text_default
weight: 0
settings: { }
third_party_settings: { }
field_variety_attributes:
type: string
weight: 0
label: inline
settings:
link_to_entity: false
third_party_settings: { }
hidden: { }
@@ -0,0 +1,20 @@
langcode: en
status: true
dependencies:
config:
- comment.type.migrate_example_advanced_comment
- field.storage.comment.comment_body
module:
- text
id: comment.migrate_example_advanced_comment.comment_body
field_name: comment_body
entity_type: comment
bundle: migrate_example_advanced_comment
label: Comment
description: ''
required: true
translatable: true
default_value: { }
default_value_callback: ''
settings: { }
field_type: text_long
@@ -0,0 +1,21 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.body
- node.type.migrate_example_producer
module:
- text
id: node.migrate_example_producer.body
field_name: body
entity_type: node
bundle: migrate_example_producer
label: Body
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
display_summary: true
field_type: text_with_summary
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_wine_regio
- node.type.migrate_example_producer
- taxonomy.vocabulary.migrate_example_wine_regions
id: node.migrate_example_producer.field_migrate_example_wine_regio
field_name: field_migrate_example_wine_regio
entity_type: node
bundle: migrate_example_producer
label: 'Migrate Example Wine Regions'
description: 'Select the region this wine comes from'
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
migrate_example_wine_regions: migrate_example_wine_regions
sort:
field: _none
auto_create: false
field_type: entity_reference
@@ -0,0 +1,21 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.body
- node.type.migrate_example_wine
module:
- text
id: node.migrate_example_wine.body
field_name: body
entity_type: node
bundle: migrate_example_wine
label: Body
description: ''
required: false
translatable: true
default_value: { }
default_value_callback: ''
settings:
display_summary: true
field_type: text_with_summary
@@ -0,0 +1,37 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_adv_image
- node.type.migrate_example_wine
module:
- image
id: node.migrate_example_wine.field_migrate_example_adv_image
field_name: field_migrate_example_adv_image
entity_type: node
bundle: migrate_example_wine
label: Image
description: 'Upload an image to go with this wine.'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
file_directory: field/migrate_example/image
file_extensions: 'png gif jpg jpeg'
max_filesize: ''
max_resolution: ''
min_resolution: ''
alt_field: true
alt_field_required: false
title_field: false
title_field_required: false
default_image:
uuid: ''
alt: ''
title: ''
width: null
height: null
handler: 'default:file'
handler_settings: { }
field_type: image
@@ -0,0 +1,32 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_comments
- node.type.migrate_example_wine
module:
- comment
id: node.migrate_example_wine.field_migrate_example_comments
field_name: field_migrate_example_comments
entity_type: node
bundle: migrate_example_wine
label: Comments
description: ''
required: false
translatable: false
default_value:
-
status: 2
cid: 0
last_comment_timestamp: 0
last_comment_name: null
last_comment_uid: 0
comment_count: 0
default_value_callback: ''
settings:
default_mode: 1
per_page: 50
anonymous: 0
form_location: true
preview: 1
field_type: comment
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_top_vintag
- node.type.migrate_example_wine
id: node.migrate_example_wine.field_migrate_example_top_vintag
field_name: field_migrate_example_top_vintag
entity_type: node
bundle: migrate_example_wine
label: 'Recommended vintages'
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
max: null
prefix: ''
suffix: ''
field_type: integer
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_wine_best
- node.type.migrate_example_wine
- taxonomy.vocabulary.migrate_example_wine_best_with
id: node.migrate_example_wine.field_migrate_example_wine_best
field_name: field_migrate_example_wine_best
entity_type: node
bundle: migrate_example_wine
label: 'Migrate Example Wine Best With'
description: 'Enter any foods this wine may be paired with, separated by commas'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
migrate_example_wine_best_with: migrate_example_wine_best_with
sort:
field: _none
auto_create: false
field_type: entity_reference
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_wine_ratin
- node.type.migrate_example_wine
id: node.migrate_example_wine.field_migrate_example_wine_ratin
field_name: field_migrate_example_wine_ratin
entity_type: node
bundle: migrate_example_wine
label: Rating
description: 'Rating on a 1-100 scale'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
min: !!float 1
max: !!float 100
prefix: ''
suffix: ''
field_type: decimal
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_wine_regio
- node.type.migrate_example_wine
- taxonomy.vocabulary.migrate_example_wine_regions
id: node.migrate_example_wine.field_migrate_example_wine_regio
field_name: field_migrate_example_wine_regio
entity_type: node
bundle: migrate_example_wine
label: 'Migrate Example Wine Regions'
description: 'Select the region this wine comes from'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
migrate_example_wine_regions: migrate_example_wine_regions
sort:
field: _none
auto_create: false
field_type: entity_reference
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_migrate_example_wine_var
- node.type.migrate_example_wine
- taxonomy.vocabulary.migrate_example_wine_varieties
id: node.migrate_example_wine.field_migrate_example_wine_var
field_name: field_migrate_example_wine_var
entity_type: node
bundle: migrate_example_wine
label: 'Migrate Example Wine Varieties'
description: 'Select the variety of this wine'
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:taxonomy_term'
handler_settings:
target_bundles:
migrate_example_wine_varieties: migrate_example_wine_varieties
sort:
field: _none
auto_create: false
field_type: entity_reference
@@ -0,0 +1,18 @@
langcode: en
status: true
dependencies:
config:
- field.storage.taxonomy_term.field_variety_attributes
- taxonomy.vocabulary.migrate_example_wine_varieties
id: taxonomy_term.migrate_example_wine_varieties.field_variety_attributes
field_name: field_variety_attributes
entity_type: taxonomy_term
bundle: migrate_example_wine_varieties
label: Attributes
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings: { }
field_type: string
@@ -0,0 +1,32 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- file
- image
- node
id: node.field_migrate_example_adv_image
field_name: field_migrate_example_adv_image
entity_type: node
type: image
settings:
uri_scheme: public
default_image:
uuid: ''
alt: ''
title: ''
width: null
height: null
target_type: file
display_field: false
display_default: false
module: image
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- comment
- node
id: node.field_migrate_example_comments
field_name: field_migrate_example_comments
entity_type: node
type: comment
settings:
comment_type: migrate_example_advanced_comment
module: comment
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- node
id: node.field_migrate_example_top_vintag
field_name: field_migrate_example_top_vintag
entity_type: node
type: integer
settings:
unsigned: false
size: normal
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- node
- taxonomy
id: node.field_migrate_example_wine_best
field_name: field_migrate_example_wine_best
entity_type: node
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- node
id: node.field_migrate_example_wine_ratin
field_name: field_migrate_example_wine_ratin
entity_type: node
type: decimal
settings:
precision: 10
scale: 0
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- node
- taxonomy
id: node.field_migrate_example_wine_regio
field_name: field_migrate_example_wine_regio
entity_type: node
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- node
- taxonomy
id: node.field_migrate_example_wine_var
field_name: field_migrate_example_wine_var
entity_type: node
type: entity_reference
settings:
target_type: taxonomy_term
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,23 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
module:
- taxonomy
id: taxonomy_term.field_variety_attributes
field_name: field_variety_attributes
entity_type: taxonomy_term
type: string
settings:
max_length: 255
is_ascii: false
case_sensitive: false
module: core
locked: false
cardinality: -1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
name: 'Wine Producer'
type: migrate_example_producer
description: 'Wineries, vineyards, and large producers.'
help: ''
new_revision: false
preview_mode: 1
display_submitted: true
@@ -0,0 +1,13 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
name: Wine
type: migrate_example_wine
description: 'Wine is what we drink.'
help: ''
new_revision: false
preview_mode: 1
display_submitted: true
@@ -0,0 +1,14 @@
dependencies:
enforced:
module:
- migrate_example_advanced_setup
id: migrate_example_advanced_position
plugin_id: 'migrate_example_advanced_position'
granularity: method
configuration:
GET:
supported_formats:
- json
- xml
supported_auth:
- cookie
@@ -0,0 +1,14 @@
dependencies:
enforced:
module:
- migrate_example_advanced_setup
id: migrate_example_advanced_variety_items
plugin_id: 'migrate_example_advanced_variety_items'
granularity: method
configuration:
GET:
supported_formats:
- json
- xml
supported_auth:
- cookie
@@ -0,0 +1,14 @@
dependencies:
enforced:
module:
- migrate_example_advanced_setup
id: migrate_example_advanced_variety_list
plugin_id: 'migrate_example_advanced_variety_list'
granularity: method
configuration:
GET:
supported_formats:
- json
- xml
supported_auth:
- cookie
@@ -0,0 +1,14 @@
dependencies:
enforced:
module:
- migrate_example_advanced_setup
id: migrate_example_advanced_variety_multiple
plugin_id: 'migrate_example_advanced_variety_multiple'
granularity: method
configuration:
GET:
supported_formats:
- json
- xml
supported_auth:
- cookie
@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
name: 'Migrate Example Wine Best With'
vid: migrate_example_wine_best_with
description: 'Foods the wine goes best with'
hierarchy: 0
weight: 0
@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
name: 'Migrate Example Wine Regions'
vid: migrate_example_wine_regions
description: 'Wine regions'
hierarchy: 0
weight: 0
@@ -0,0 +1,11 @@
langcode: en
status: true
dependencies:
enforced:
module:
- migrate_example_advanced_setup
name: 'Migrate Example Wine Varieties'
vid: migrate_example_wine_varieties
description: 'Wine varieties'
hierarchy: 0
weight: 0
@@ -0,0 +1,17 @@
type: module
name: Migrate Advanced Example Setup
description: 'Separate site configuration for the example from the actual migration.'
package: Migration
core_version_requirement: '>=9.1'
hidden: true
dependencies:
- drupal:comment
- drupal:image
- drupal:text
- drupal:taxonomy
- drupal:rest
# Information added by Drupal.org packaging script on 2024-11-20
version: '6.0.5'
project: 'migrate_plus'
datestamp: 1732124626
@@ -0,0 +1,44 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
/**
* Represents positions as resources.
*
* @RestResource(
* id = "migrate_example_advanced_position",
* label = @Translation("Advanced migration example - Position data"),
* uri_paths = {
* "canonical" = "/migrate_example_advanced_position"
* }
* )
*/
final class PositionResource extends ResourceBase {
/**
* Responds to GET requests.
*
* The response containing the position data.
*/
public function get(): ResourceResponse {
$position1 = ['sourceid' => 'wine_taster', 'name' => 'Wine Taster'];
$position2 = ['sourceid' => 'vintner', 'name' => 'Vintner'];
$data = ['position' => [$position1, $position2]];
return new ResourceResponse($data, 200);
}
/**
* {@inheritdoc}
*/
public function permissions(): array {
// Remove permissions so the resource is available to all.
return [];
}
}
@@ -0,0 +1,76 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
/**
* Provides varieties as two endpoints, one for reds and one for whites.
*
* @RestResource(
* id = "migrate_example_advanced_variety_items",
* label = @Translation("Advanced migration example - Variety data"),
* uri_paths = {
* "canonical" = "/migrate_example_advanced_variety_list/{variety}"
* }
* )
*/
final class VarietyItems extends ResourceBase {
/**
* Responds to GET requests.
*
* @param string|null $variety
* Machine name of the variety to retrieve.
*
* The response containing the requested variety data.
*/
public function get(?string $variety = NULL): ResourceResponse {
$varieties = [
'retsina' => [
'name' => 'Retsina',
// The categoryid for 'white'.
'parent' => 1,
'details' => 'Greek',
],
'trebbiano' => [
'name' => 'Trebbiano',
// The categoryid for 'white'.
'parent' => 1,
'details' => 'Italian',
],
'valpolicella' => [
'name' => 'Valpolicella',
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
],
'bardolino' => [
'name' => 'Bardolino',
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
],
];
if (isset($varieties[$variety])) {
$data = ['variety' => $varieties[$variety]];
}
else {
$data = [];
}
return new ResourceResponse($data, 200);
}
/**
* {@inheritdoc}
*/
public function permissions(): array {
// Remove permissions so the resource is available to all.
return [];
}
}
@@ -0,0 +1,43 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
/**
* Provides varieties as two endpoints, one for reds and one for whites.
*
* @RestResource(
* id = "migrate_example_advanced_variety_list",
* label = @Translation("Advanced migration example - Variety list of data"),
* uri_paths = {
* "canonical" = "/migrate_example_advanced_variety_list"
* }
* )
*/
final class VarietyList extends ResourceBase {
/**
* Responds to GET requests.
*
* The response containing the requested variety data.
*/
public function get(): ResourceResponse {
$data = [];
$data['items'] = ['retsina', 'trebbiano', 'valpolicella', 'bardolino'];
return new ResourceResponse($data, 200);
}
/**
* {@inheritdoc}
*/
public function permissions(): array {
// Remove permissions so the resource is available to all.
return [];
}
}
@@ -0,0 +1,85 @@
<?php
namespace Drupal\migrate_example_advanced_setup\Plugin\rest\resource;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
/**
* Provides varieties as two endpoints, one for reds and one for whites.
*
* @RestResource(
* id = "migrate_example_advanced_variety_multiple",
* label = @Translation("Advanced migration example - Variety data"),
* uri_paths = {
* "canonical" = "/migrate_example_advanced_variety_multiple/{type}"
* }
* )
*/
class VarietyMultiFiles extends ResourceBase {
/**
* Responds to GET requests.
*
* @param string|null $type
* 'red', 'white', or NULL to return all varieties.
*
* The response containing the requested variety data.
*/
public function get(?string $type = NULL): ResourceResponse {
$data = [];
if (strtolower($type) != 'white') {
$data['variety'][] = [
'name' => 'Amarone',
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Venoto region',
'attributes' => [
'rich',
'aromatic',
],
];
$data['variety'][] = [
'name' => 'Barbaresco',
// The categoryid for 'red'.
'parent' => 3,
'details' => 'Italian Piedmont region',
'attributes' => [
'smoky',
'earthy',
],
];
}
if (strtolower($type) != 'red') {
$data['variety'][] = [
'name' => 'Kir',
// The categoryid for 'white'.
'parent' => 1,
'details' => 'French Burgundy region',
'attributes' => [],
];
$data['variety'][] = [
'name' => 'Pinot Grigio',
// The categoryid for 'white'.
'parent' => 1,
'details' => 'From the northeast of Italy',
'attributes' => [
'fruity',
'medium-bodied',
'slightly sweet',
],
];
}
return new ResourceResponse($data, 200);
}
/**
* {@inheritdoc}
*/
public function permissions(): array {
// Remove permissions so the resource is available to all.
return [];
}
}
@@ -0,0 +1,58 @@
<?php
declare(strict_types = 1);
namespace Drupal\migrate_example_advanced\Plugin\migrate\source;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
/**
* A SQL-based source plugin, to retrieve category data from a source database.
*
* @MigrateSource(
* id = "wine_term"
* )
*/
final class WineTerm extends SqlBase {
/**
* {@inheritdoc}
*/
public function query(): SelectInterface {
$fields = [
'categoryid',
'type',
'name',
'details',
'category_parent',
'ordering',
];
return $this->select('migrate_example_advanced_categories', 'wc')
->fields('wc', $fields)
// This sort assures that parents are saved before children.
->orderBy('category_parent', 'ASC');
}
/**
* {@inheritdoc}
*/
public function fields(): array {
return [
'categoryid' => $this->t('Unique ID of the category'),
'type' => $this->t('Category type corresponding to Drupal vocabularies'),
'name' => $this->t('Category name'),
'details' => $this->t('Description of the category'),
'category_parent' => $this->t('ID of the parent category'),
'ordering' => $this->t('Order in which to display this category'),
];
}
/**
* {@inheritdoc}
*/
public function getIds(): array {
return ['categoryid' => ['type' => 'integer']];
}
}
@@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\migrate_example_advanced\Functional;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\BrowserTestBase;
/**
* Tests migrate_example_advanced migrations.
*
* @group migrate_plus
*/
class MigrateExampleAdvancedTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'node',
'taxonomy',
'path',
'migrate_plus',
'migrate_example_advanced',
'migrate_example_advanced_setup',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests whether the module can be uninstalled and installed again.
*
* Also, checks whether the example configs are removed after uninstall.
*/
public function testModuleCleanup(): void {
$test_node_type = 'migrate_example_producer';
// Prove that test content type existed before the uninstall process.
$this->assertInstanceOf(NodeType::class, NodeType::load($test_node_type));
\Drupal::service('module_installer')->uninstall(['migrate_example_advanced_setup']);
// Make sure the test content type was removed.
$this->assertNull(NodeType::load($test_node_type));
// Check whether test configuration files were removed.
\Drupal::service('module_installer')->install(['migrate_example_advanced_setup']);
}
}