Add redirects migration
This commit is contained in:
parent
34db78bf47
commit
eedf06aa3e
6 changed files with 398 additions and 1 deletions
|
@ -0,0 +1,51 @@
|
|||
id: redirect
|
||||
|
||||
source:
|
||||
plugin: url
|
||||
data_fetcher_plugin: http
|
||||
data_parser_plugin: json
|
||||
|
||||
urls: https://deploy-preview-213--opdavies.netlify.app/redirects.json
|
||||
|
||||
ids:
|
||||
id:
|
||||
type: integer
|
||||
|
||||
item_selector: redirects/
|
||||
|
||||
fields:
|
||||
- name: id
|
||||
selector: id
|
||||
label: Redirect ID
|
||||
|
||||
- name: from
|
||||
selector: from
|
||||
label: From
|
||||
|
||||
- name: to
|
||||
selector: to
|
||||
label: To
|
||||
|
||||
process:
|
||||
redirect_source/path: from
|
||||
redirect_redirect/uri:
|
||||
plugin: opd_redirect
|
||||
source: to
|
||||
|
||||
language:
|
||||
plugin: default_value
|
||||
default_value: und
|
||||
|
||||
status_code:
|
||||
plugin: default_value
|
||||
default_value: 301
|
||||
|
||||
uid:
|
||||
plugin: default_value
|
||||
default_value: 1
|
||||
|
||||
destination:
|
||||
plugin: 'entity:redirect'
|
||||
|
||||
migration_dependencies:
|
||||
required: { }
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\custom\Plugin\migrate\process;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* Perform custom value transformations.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "opd_redirect"
|
||||
* )
|
||||
*/
|
||||
class OpdRedirect extends ProcessPluginBase {
|
||||
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
if (Str::startsWith($value, '/')) {
|
||||
return "internal:{$value}";
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue