0

I'm trying to write a custom source plugin for a d7-d8 migration. I want to extend the Drupal\node\Plugin\migrate\source\d7 Node.php plugin.

I'm getting the following error when I try to run the migration from the UI:

Migration my_node_page did not meet the requirements. The module my_xtra is not enabled in the source site. source_module: my_xtra.

When I run drush ms I get a different error

No database connection configured for source plugin variable

The database connection key is specified in the group yml and works for other migrations which don't use the custom source plugin.

Here's my yml file

id: my_node_page
label: Node Basic Page
audit: true
migration_tags:
  - Drupal 7
  - Content
migration_group: my_group
source:
  plugin: my_xtra_node
  node_type: 'page'
process:

Here's my custom plugin.

    <?php
    
    namespace Drupal\my_extra\Plugin\migrate\source;
    
    use Drupal\node\Plugin\migrate\source\d7\Node;
    
    /**
     * Drupal 7 node source from database.
     *
     * @MigrateSource(
     *   id = "my_xtra_node",
     *   source_provider = "node",
     *   source_module = "my_xtra",
     *   
     * )
     */
    class NodeXtra extends Node {
    
    
      /**
       * {@inheritdoc}
      */
      public function query() {
        // Select node in its last revision.
        $query = $this->select('node_revision', 'nr')
          ->fields('n', [
            'nid',
            'type',
            'language',
            'status',
            'created',
            'changed',
            'comment',
            'promote',
            'sticky',
            'tnid',
            'translate',
          ])
          ->fields('nr', [
            'vid',
            'title',
            'log',
            'timestamp',
          ]);
        $query->addField('n', 'uid', 'node_uid');
        $query->addField('nr', 'uid', 'revision_uid');
        $query->innerJoin('node', 'n', static::JOIN);
    
        // If the content_translation module is enabled, get the source langcode
        // to fill the content_translation_source field.
        if ($this->moduleHandler->moduleExists('content_translation')) {
          $query->leftJoin('node', 'nt', 'n.tnid = nt.nid');
          $query->addField('nt', 'language', 'source_langcode');
        }
        $this->handleTranslations($query);
    
        if (isset($this->configuration['node_type'])) {
          $query->condition('n.type', $this->configuration['node_type']);
        }
    
        return $query;
      } 
}

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.