Processing publish states of elements definitely sounds easier than it is.
In V1 of this bundle, there was a object_ignore_unpublished
and object_ignore_unpublished
option flag.
Back then, trinity skipped unpublished objects by default.
In V2 we're fetching unpublished elements by default. If we wouldn't allow unpublished elements, they would stay forever in index. Imagine an published element which is published at index time. But if you're going to unpublish it, and maybe you're editing this element afterwards, it wil never get updated again, because the internal validator would disallow unpublished elements.
So what can you do? There are two options:
You could fetch every document regardless its state. You could add a published
flag to your document definition
and filter by this flag in your frontend query.
Within the DynamicSearchEvents::RESOURCE_CANDIDATE_VALIDATION
event, you're able to modify the state of resource.
So for example, you could disallow to fetch the unpublished element at index
or insert
operations but allow it to modify/delete it
on update
or delete
operations. Read more about the resource validator here.