-
-
Save chx/232ba2d2bb32ceb2eef68045d54bb53b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\sd8_migration\Plugin\migrate\process; | |
use Drupal\migrate\MigrateExecutableInterface; | |
use Drupal\migrate\ProcessPluginBase; | |
use Drupal\migrate\Row; | |
/** | |
* @MigrateProcessPlugin( | |
* id = "sd8_metatag" | |
* ) | |
*/ | |
class Metatag extends ProcessPluginBase { | |
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { | |
if ($value = @unserialize($value)) { | |
foreach ($value as $name => $data) { | |
if (!empty($data['value'])) { | |
$metatag[$this->configuration['map'][$name]] = $data['value']; | |
} | |
} | |
} | |
return !empty($metatag) ? serialize($metatag) : NULL; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tags = \Drupal::service('plugin.manager.metatag.tag')->getDefinitions(); | |
$definition['process']['meta_tags'] = [ | |
'plugin' => 'sd8_metatag', | |
'source' => 'metatag', | |
'map' => array_column($tags, 'id', 'name'), | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implements hook_migrate_prepare_row(). | |
*/ | |
function sd8_migration_migrate_prepare_row(Row $row, MigrateSourceInterface $source, MigrationInterface $migration) { | |
if ($source instanceof Node) { | |
/** @var \Drupal\Core\Database\Query\SelectInterface $query */ | |
$query = $source->getDatabase()->select('metatag', 'm') | |
->fields('m', ['data']) | |
->condition('entity_type', 'node') | |
->condition('entity_id', $row->getSourceProperty('nid')) | |
->condition('revision_id', $row->getSourceProperty('vid')) | |
->condition('language', $row->getSourceProperty('language')); | |
$row->setSourceProperty('metatag', $query->execute()->fetchField()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment