I am setting up a system where one Drupal site serves as a Canonical source for specific content for a group of other Drupal sites to import from. I wanted to use the built-in Drupal JSON:API and Drupal Migration system to do this, but have had trouble figuring out how to properly import entity reference fields.
The Drupal JSON:API returns entity reference field data from a node as a relationship data set. It does not include the data for the entity referenced, just a separate API URL to request the data. For example an image reference returns this:
"relationships": {
"news_banner": {
"data": null,
"links": {
"related": {
"href": "SITEURL/jsonapi/node/news/69f1dfc0-5f83-4bfc-9520-1688782cfb12/news_banner?resourceVersion=id%3A40756"
},
"self": {
"href": "SITEURL/jsonapi/node/news/69f1dfc0-5f83-4bfc-9520-1688782cfb12/relationships/news_banner?resourceVersion=id%3A40756"
}
}
},
From what I have found, the Drupal Migration System nor the migrate_plus
module have an out of the box method to make sub-requests as part of the original migration. Additionally, the JSON:API nor the jsonapi_extras
module have an out of the box method to return the data for referenced entities/relationships as part of the larger request.
The method I've seen documented for the Migration System is
to chain multiple migrations together β
. This method uses a separate migration to pull the entities referenced later and then link them back to the parent entity using a migration_lookup
plugin. However, this method does not have a means to pull only the referenced entities you need to pull from the previous migration. It does not seem intended to run sub-requests from a previous migration to "fill in the blanks", but to migrate ALL data from a source and link the data together.
Is there a way to do a sub-request as part of a Drupal Migration or to expose referenced entity data as part of a single JSON:API request without writing custom code?
I am tempted to create a View that returns the JSON data required with Contextual Filters to allow filtering of the response. But I was hoping to avoid creating yet another View and that Drupal Core would have an out of the box solution for this type of data transfer between multiple Drupal instances.
Active
10.3 β¨