目前,我正在将Drupal 7站点迁移到Drupal 9,站点中的节点的内容类似于下面的内容。
WHAT WILL YOUR NEXT MEAL BE?
[embed]https://www.youtube.com/watch?v=Np28O3Y_P2o[/embed]
Lorem Ipsum is simply dummy text of the printing and typesetting industry galley of type and Lorem Ipsum我尝试使用Rich过滤器将值转储到Body字段中,但是节点显示时使用的是[embed]和[/embed]之间的链接,而不是呈现项。
谁能建议一个迁移插件或者将
[embed]https://www.youtube.com/watch?v=Np28O3Y_P2o[/embed]
转换成Drupal9Media实体的方法呢?
发布于 2021-09-29 15:49:56
我不知道这种情况下的插件。
但你可以编写您的自定义插件。
在自定义插件中,您需要通过正则表达式解析文本并手动创建youtube媒体实体。
下面是一些代码示例,为您指出正确的方向。
迁移过程插件将解析文本,并处理嵌入部分:
$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.
}
}在createYoutubeEmbed方法中,您需要
这是我在迁移中实现的媒体图像嵌入的一个示例:
/**
* 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 = ' $value) {
$embed .= " $key=\"$value\"";
}
$embed .= '>';
return $embed;
}https://drupal.stackexchange.com/questions/307378
复制相似问题