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.

Comments

bojanz created an issue. See original summary.

bojanz’s picture

I 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?

drunken monkey’s picture

Component: General code » Plugins
Status: Active » Needs review
StatusFileSize
new1.57 KB

I could use \Drupal::entityTypeManager() but that's a bit unclean. Thoughts?

Well, 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 status property, 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.

Status: Needs review » Needs work

The last submitted patch, 3: 2907756-3--entity_status_published_interface.patch, failed testing. View results

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new1.83 KB
new3.4 KB
borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This looks great!

bojanz’s picture

Indeed, it does.
Thank you, Thomas.

  • drunken monkey committed 01f16fb on 8.x-1.x
    Issue #2907756 by drunken monkey, bojanz: Fixed "Entity status"...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Good to hear, thanks for reviewing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.