I’m developing a module in Drupal 8 to create a custom content entity that pulls document information from an external MySQL database located on the same server. The idea is to define each document as an entity, pull data from each entity into views, use Search API to create a search index, and then use views to to view the search results. We have meta data for about 150,000 documents on our external database and we want to use Drupal as a search interface for those documents.
So far, I’ve used Drupal content to create a basic module that defines my custom entity. After creating it, I figured out how to use views, Search API, and generate search results using a few locally created custom entity examples.
However, I have not been able to figure out how I can pull the document information from my external database into Drupal as entities. I have connected to the external database in my settings.php and have verified the connection is working. I understand how to switch to that database within my module and run SQL queries. But I have not been able to figure out where and how in my module to connect to the external database and create the entities instances.
Is there a specific location within a generic custom content entity module to tell Drupal to retrieve information for the new entity class from the external database? Relatedly, how do I tell Drupal in the module to map specific document metadata to corresponding entity fields?
I’ve also looked at several modules as alternatives to a custom module: External entities, Views Database Connector, and Remote Entity API, among others. Most that I have found do not yet have a working Drupal 8 module or the module is only in development. I’ve tried the few that seem most relevant (esp. external entities) but have not been able to get those implemented.
I’m still new to Drupal, so if there is a better way to make our documents searchable or I’m mistaken on anything here, please let me know.