11/30/2021

Entity_reference_revisions Drupal 8

As of Fall 2018 and the release of Drupal 8.6, the Migrate module in core is finally stabilizing! Hopefully Migrate documentation will continue to solidify, but there are plenty of gaps to fill.

  1. Entity_reference_revisions Drupal 8 0
  2. Drupal 8 Entity Type Manager
  3. Entity_reference_revisions Drupal 8 Download

Recently, I ran into an issue migrating Paragraph Entities (Entity Reference Revisions) that had a few open core bugs and ended up being really simple to solve within prepareRow in the source plugin.

Setup

Provide service to migrate an existing Entity Reference field to an Entity Reference Revisions field: Active: Normal: Feature request: 8.x-1.x-dev: Code: 3: 1 year 1 month: 1 year 1 month: Add GraphQL field to allow querying of entity reference revisions fields. If you write custom Drupal 8 (or 9) modules, then you've probably used the entity QueryInterface - which is accessible from the Drupal::entityQuery static method. If not, then you're missing out on this incredibly useful tool that allows you to easily query a Drupal site for entities of any kind.

Drupal entity module
  1. Go to Drupal download page and download the version of Drupal 8. Extract and copy Drupal folder to your host and rename the directory (e.g: marketplaced8) Follow steps below to install a Drupal site only: 3. Access to database and create a new database with a name such as marketplaced8. Open browser and navigate to your website.
  2. Entity reference revisions module This module was last tested on the 25th June 2019, on Drupal 8.6.13 with DX8 5.4.7 using version 8.x-1.6 of the module. Currently there are some issues when using Entity reference revisions with DX8.
  3. Adds a Entity Reference field type with revision support. It's based on the core Entity Reference module but allows you to reference a specific entity. This is useful for modules like Paragraphs and maybe in the future for modules like Inline Entity Form and Field Collection.
In my destination D8 site, I had a content type with a Paragraph reference field. Each node contained one or more Paragraph entities. This was reflected by having a Node migration with a dependency on a Paragraph Entity migration.Revisions

With single value entity references, the migration_lookup plugin makes it really easy lookup up entity reference identifiers that were previously imported. As of September 2018, there is an open core issue to allow multiple values with migration_lookup. Migration lookup uses the migration map table created in the database to connect previously migrated data to Drupal data. The example below lookups up the taxonomy term ID based on the source reference (topic_area_id) from a previously ran migration. Note: You will need to add a migration dependency to your migration yml file to make sure migrations are run in the correct order.

Solution

Without using a Drupal Core patch, we need a way to do a migration_lookupEntity_reference_revisions in a more manual way. Thankfully

Entity_reference_revisions Drupal 8 0

prepareRow in your Migrate source plugin makes this pretty easy.

Note: This is not a complete Migrate source plugin. All the methods are there, but I’m focussing on the prepareRow method for this post. The most important part of the code is manually querying the Migrate map database table created in the Paragraph Entity migration.

In your migration yml file, you can reference the prepare_multiple_paragraphs that was created in the migrate source plugin like this:

Drupal 8 Entity Type Manager

Drupal

Entity_reference_revisions Drupal 8 Download

Sub_process was formally the iterator plugin and allows you to loop over items. This will properly create references to multiple Paragraph Entities. It will be nice when the migration_lookup plugin can properly handle this use case, but it’s a good thing to understand how prepareRow can provide flexibility.