I am not aware about any plugins for this case.
But you can write your custom plugin.
In the custom plugin you will need to parse text by a regular expression and create youtube media entities from it manually.
Here are some code examples to point you to a right direction.
The migration process plugin will parse the text, and process embed parts:
<?php
namespace Drupal\my_migrate\Plugin\migrate\process;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\Row;
/**
* Provides a body text migrate process plugin.
*
* @MigrateProcessPlugin(
* id = "body_text"
* )
*/
class BodyText extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$body = '';
if (preg_match_all('/[embed](.*)[/embed]/Usi', $text, $matches)) {
// Text parts splitted by embeds.
$text_parts = preg_split('/[embed](.*)[/embed]/Usi', $text);
$body = $text_parts[0];
unset($text_parts[0]);
$text_parts = array_values($text_parts);
// Loop text parts, create media embeds.
foreach ($text_parts as $key => $text_part) {
if (isset($matches[1][$key])) {
$embed = $matches[1][$key];
if (!$text) {
$this->addTag(MigrationTags::TAG_MISSING_QUOTE);
}
$body .= $this->createYoutubeEmbed($embed);
}
$body .= $text_part;
}
}
return $body;
}
protected function createYoutubeEmbed($embed) {
// 1. Create youtube media entity using the URL.
// 2. Generate media embed.
}
}
In the createYoutubeEmbed
method you will need to
- Create youtube media entity using the URL.
- Generate media embed. To figure out how the youtube media embed should look like, create some content in Drupal manually and see the source code in the CKEditor.
This is an example for media image embed that I implemented in my migration:
/**
* Creates media image embed for text paragraphs.
*
* @param \Drupal\media\MediaInterface $media
* The media image.
* @param string $align
* (optional) The image alignment, allowed values: left, right, center.
* @param string $display
* (optional) The image display variant. Allowed values: large (default),
* medium, small.
* @param string $link
* (optional) Link URL.
*
* @return string
* The embed code.
*/
protected function createMediaImageEmbed(MediaInterface $media, $align = '', $display = 'large', $link = NULL) {
$attributes = [
'data-embed-button' => $media->bundle(),
'data-entity-embed-display' => 'view_mode:media.' . $display,
'data-align' => $align,
'data-entity-type' => 'media',
'data-entity-uuid' => $media->uuid(),
'data-langcode' => 'de',
];
if ($link) {
$link = str_replace("/", "\/", $link);
$attributes['data-entity-embed-display-settings'] = '{"link_url":"' . $link . '\/","link_url_target":0}';
}
$embed = '<drupal-entity';
foreach ($attributes as $key => $value) {
$embed .= " $key=\"$value\"";
}
$embed .= '></drupal-entity>';
return $embed;
}