The code that does the limiting (alterIndexedItems) is already generic.
However, the list of entity type IDs is hardcoded:
public static function supportsIndex(IndexInterface $index) {
$supported_entity_types = ['node', 'comment', 'user'];
foreach ($index->getDatasources() as $datasource) {
if (in_array($datasource->getEntityTypeId(), $supported_entity_types)) {
We can improve this.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 2907756-5--entity_status_published_interface.patch | 3.4 KB | drunken monkey |
Comments
Comment #2
bojanz commentedI just realized supportsIndex() is static, so I can't inject the entity type manager and use it to check if the entity type class of a given entity type ID implements the EntityPublishedInterface. I could use \Drupal::entityTypeManager() but that's a bit unclean. Thoughts?
Comment #3
drunken monkeyWell, what else could you do? Proper DI just isn't possible in all cases.
The attached patch should implement this. Thanks a lot for the suggestion!
We might also just look for a
statusproperty, I guess, instead of all the current logic. And maybe make the affected datasources configurable, to avoid unintended effects. But that would be another issue, I guess.Comment #5
drunken monkeyComment #6
borisson_This looks great!
Comment #7
bojanz commentedIndeed, it does.
Thank you, Thomas.
Comment #9
drunken monkeyGood to hear, thanks for reviewing!
Committed.