getDatasources() as $datasource) { $entity_type_id = $datasource->getEntityTypeId(); if (!$entity_type_id) { continue; } // We support users and any entities that implement // \Drupal\Core\Entity\EntityPublishedInterface. if ($entity_type_id === 'taxonomy_term') { return TRUE; } // $entity_type = \Drupal::entityTypeManager() // ->getDefinition($entity_type_id); // if ($entity_type && $entity_type->entityClassImplements($interface)) { // return TRUE; // } } return FALSE; } /** * {@inheritdoc} */ public function alterIndexedItems(array &$items) { // Annoyingly, this doc comment is needed for PHPStorm. See // http://youtrack.jetbrains.com/issue/WI-23586 /** @var \Drupal\search_api\Item\ItemInterface $item */ foreach ($items as $item_id => $item) { $term = $item->getOriginalObject()->getValue(); $enabled = TRUE; // $entity_storage = \Drupal::entityTypeManager()->getStorage('node'); // $count_query = $entity_storage->getQuery() // ->condition('type', 'materiau') // ->accessCheck(TRUE) // ->condition('status', '1') // ->count(); // // $this->count = $this->count_query->execute(); $query = \Drupal::database()->select('taxonomy_index', 'ti'); $query->fields('ti', array('nid')); $query->condition('ti.tid', $term->id()); $query->distinct(TRUE); $result = $query->execute(); $nodeIds = $result->fetchCol(); if (!$nodeIds) { unset($items[$item_id]); } } } }