1

I have a custom content entity that has been setup with several properties declared. This was really nothing special, just a standard entity representation of data from a custom table in the Drupal database. Everything worked as expected (CRUD operations, views integration, etc.).

This was initially just a test however. The table behind this entity needs to live in a separate MySQL database. This database will be on the same sever as the Drupal database, but must be managed independently with write operations initiated from separate platforms. To attempt this I simply modified the relevant part of the entity annotation from:

base_table = "mytable",

To:

base_table = "mydb.mytable",
persistent_cache = FALSE,

The first line declares the base table inside the separate DB (also discussed here) and the second line bypasses local entity caching so fresh data is always displayed in Drupal (also discussed here). For the most part this also works great and seems fully compatible with Drupal's entity API (CRUD operations still work as expected). The issue is that views integration now fails. I can still create a new view based my content entity, but no properties are available (not even the base ID). If I attempt to alter a view created before changing the annotations all properties result in broken handlers and query errors, in the same manner as describe in this question (which is similar, though related to the prefixing of the base table, not fetching it from a separate database).

There are certainly projects in the contrb space that attempt to integrate views with external/remote data, and I always have the option to use search_api as an intermediary between my custom content entity and views, but I'd like to see if there is a native Drupal 8 core solution for this. Given that the main entity APIs appear to support entity data from another database just fine I was hopeful views support would be implied. Are there alterations required to my entity delcaration (perhaps something in the extended \Drupal\views\EntityViewsData object for my custom entity) to get this working?

1 Answer 1

0

Further research has led to the conclusion that this is a current limitation in views. Special characters are not escaped correctly in table names, specifically the "." separator notation in dbname.tablename. It could be framed as a bug depending on what sources views officially supports in core. I've opened an issue with more details:

https://www.drupal.org/node/2904787

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.