Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D7 migration template and plugins. #97

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions migration_templates/d7_path_redirect.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
id: d7_path_redirect
label: Path Redirect
migration_tags:
- Drupal 7
source:
plugin: d7_path_redirect
process:
rid: rid
uid: uid
redirect_source/path: source
redirect_source/query:
plugin: d7_redirect_source_query
source: source_options
redirect_redirect/uri:
plugin: d7_path_redirect
source:
- redirect
- redirect_options
language:
plugin: default_value
source: language
default_value: und
status_code: status_code
destination:
plugin: entity:redirect
51 changes: 51 additions & 0 deletions src/Plugin/migrate/process/d7/PathRedirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/**
* @file
* Contains \Drupal\redirect\Plugin\migrate\process\d7\PathRedirect.
*/

namespace Drupal\redirect\Plugin\migrate\process\d7;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
* @MigrateProcessPlugin(
* id = "d7_path_redirect"
* )
*/
class PathRedirect extends ProcessPluginBase {

/**
* {@inheritdoc}
*
* Transform the field as required for an iFrame field.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

// Check if the url begins with http.
if (preg_match('#^http#', $value[0])) {
// Use it as is.
$uri = $value[0];
}
else {
// Make the link internal.
$uri = 'internal:/' . $value[0];
}

// Check if there are options.
if (!empty($value[1])) {
// Check if there is a query.
$options = unserialize($value[1]);
if (!empty($options['query'])) {
// Add it to the end of the url.
$uri .= '?' . http_build_query($options['query']);
}
}

return $uri;
}

}
41 changes: 41 additions & 0 deletions src/Plugin/migrate/process/d7/RedirectSourceQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* @file
* Contains \Drupal\redirect\Plugin\migrate\process\d7\RedirectSourceQuery.
*/

namespace Drupal\redirect\Plugin\migrate\process\d7;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
* @MigrateProcessPlugin(
* id = "d7_redirect_source_query"
* )
*/
class RedirectSourceQuery extends ProcessPluginBase {

/**
* {@inheritdoc}
*
* Transform the field as required for an iFrame field.
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {

// Check if there are options.
if (!empty($value)) {
// Check if there is a query.
$options = unserialize($value);
if (!empty($options['query'])) {
// Add it to the end of the url.
return serialize($options['query']);
}
}

return NULL;
}

}
58 changes: 58 additions & 0 deletions src/Plugin/migrate/source/d7/PathRedirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* @file
* Contains \Drupal\redirect\Plugin\migrate\source\d7\PathRedirect.
*/

namespace Drupal\redirect\Plugin\migrate\source\d7;

use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/**
* Drupal 7 path redirect source from database.
*
* @MigrateSource(
* id = "d7_path_redirect"
* )
*/
class PathRedirect extends DrupalSqlBase {

/**
* {@inheritdoc}
*/
public function query() {
// Select path redirects.
$query = $this->select('redirect', 'p')
->fields('p');

return $query;
}

/**
* {@inheritdoc}
*/
public function fields() {
// @todo Complete this function for D7.
$fields = array(
'rid' => $this->t('Redirect ID'),
'source' => $this->t('Source'),
'redirect' => $this->t('Redirect'),
'query' => $this->t('Query'),
'fragment' => $this->t('Fragment'),
'language' => $this->t('Language'),
'type' => $this->t('Type'),
'last_used' => $this->t('Last Used'),
);
return $fields;
}

/**
* {@inheritdoc}
*/
public function getIds() {
$ids['rid']['type'] = 'integer';
return $ids;
}

}