【问题标题】:Drupal 8 migrate plugin - explanation neededDrupal 8 迁移插件 - 需要解释
【发布时间】:2017-04-18 16:44:58
【问题描述】:

我想将数据从自定义表格迁移到书籍内容类型,但是我不知道如何实现。 这是我的 config\install\migrate.migration.book_content.yml 文件:

id: book_content
label: Book content
migration_group: example
source:
  plugin: book_content
  target: db_migration
destination:
  plugin: entity:node
process:
  type:
    plugin: default_value
    default_value: article
  title: title
  uid:
    plugin: default_value
    default_value: 1
  sticky:
    plugin: default_value
    default_value: 0
  status:
    plugin: default_value
    default_value: 1
  'body/value': content
  'body/summary': excerpt
  'body/format': 
    plugin: default_value
    default_value: full_html
  # Use of the migration process plugin.
  # That will use the id map of the specified migration 
  # to retrieve the corresponding id ('source' parameter) in the destination database.
  field_description:
    plugin: migration
    source: body

src\Plugin\migrate\source\BookContent.php

<?php
/**
 * @file
 * Contains \Drupal\docapi_migrate\Plugin\migrate\source\BookContent.
 */
namespace Drupal\example_migrate\Plugin\migrate\source;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;
/**
 * Drupal 8 node from database.
 *
 * @MigrateSource(
 *   id = "book_content"
 * )
 */
class BookContent extends SqlBase {
  /**
   * {@inheritdoc}
   */
  public function query() {
    $query = $this->select('docapi_migrate', 'dm')
                  ->fields('dm', array('url', 'depth', 'body', 'meta'));
    return $query;
  }
  /**
   * {@inheritdoc}
   */
  public function fields() {
    $fields = array(
      'url' => $this->t('Content url'),
      'depth' => $this->t('Depth of the content'),
      'body' => $this->t('Full text of the content'),
      'meta' => $this->t('yaml data'),
    );
    return $fields;
  }

但是当我这样做时:

drush migrate-import book_content

我明白了:

The drush command 'migrate-import book_content' could not be found.

我不明白 BookContent.php 中的这个函数是如何工作的。 应该有带有分类参考的tags_field,但我不知道应该在哪里处理元数据,例如我得到一个标签列表。 当我有标签时,我应该如何组合它,以便迁移工作。 我正在通过谷歌搜索信息,但没有任何意义。我怎么理解这个?

【问题讨论】:

    标签: drupal drupal-modules drupal-8


    【解决方案1】:

    您的命名空间设置为example_migrate。它需要设置为您的模块的名称,因此除非模块被称为“example_migrate”,否则它无法找到该类。

    更改名称空间以匹配 YOUR_MODULE_NAME。

    namespace Drupal\YOUR_MODULE_NAME\Plugin\migrate\source;
    

    更多关于命名空间的信息可以在谷歌搜索PSR0时找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-13
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多