- 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
@mkalkbrenner I tried to use a Search API field processor.
But there was a problem, if the referenced entity is published or unpublished, then, until the entity is indexed again, the reference entity on the search index will be inconsistent, so maybe it can be done using a Search API processor, but altering the result after retrieving the items and then check the reference status, to avoid losing facet items.
The solution here is not bad, either, but it should take into account the translations.
- 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺
I created a Search API processor that should do the job https://git.drupalcode.org/project/search_api/-/merge_requests/79/diffs
I agree with @mkalkberenner that the solution proposed in the linked issue is better.
Is there any reason to keep this issue open, or could we fall back to the other one and close this?- Status changed to Closed: won't fix
about 1 year ago 10:22am 28 June 2024 - 🇧🇪Belgium borisson_ Mechelen, 🇧🇪
This is not the way, the way is in search api
- 🇮🇳India kalpanajaiswal
We encountered a similar requirement, and the following solutions worked effectively in our case:
Including unpublished nodes in the Search API index
Solution: Disable the Entity status processor in the index configuration. This ensures that unpublished nodes are not excluded during indexing.Excluding unpublished taxonomy terms from facet filters
Solution: Implement a custom Facets Processor plugin that filters out unpublished taxonomy terms during the facet build process. This allows only published terms to be displayed in the facet options, ensuring a clean and relevant user interface.<?php namespace Drupal\facets\Plugin\facets\processor; use Drupal\facets\FacetInterface; use Drupal\facets\Processor\ProcessorPluginBase; use Drupal\facets\Processor\BuildProcessorInterface; use Drupal\taxonomy\Entity\Term; /** * @FacetsProcessor( * id = "exclude_unpublished_terms", * label = @Translation("Exclude unpublished terms"), * description = @Translation("Removes unpublished taxonomy terms from facet options."), * stages = { * "build" = 50 * } * ) */ class ExcludeUnpublishedTerms extends ProcessorPluginBase implements BuildProcessorInterface { /** * {@inheritdoc} */ public function build(FacetInterface $facet, array $results): array { $filtered = []; foreach ($results as $result) { $tid = $result->getRawValue(); $term = Term::load($tid); if ($term && $term->isPublished()) { $filtered[] = $result; } } return $filtered; } } ?>