You are here

class SearchApiAlterNodeStatus in Search API 7

Exclude unpublished nodes from node indexes.

Hierarchy

Expanded class hierarchy of SearchApiAlterNodeStatus

1 string reference to 'SearchApiAlterNodeStatus'
search_api_search_api_alter_callback_info in ./search_api.module
Implements hook_search_api_alter_callback_info().

File

includes/callback_node_status.inc, line 11
Contains the SearchApiAlterNodeStatus class.

View source
class SearchApiAlterNodeStatus extends SearchApiAbstractAlterCallback {

  /**
   * Check whether this data-alter callback is applicable for a certain index.
   *
   * Returns TRUE only for indexes on nodes.
   *
   * @param SearchApiIndex $index
   *   The index to check for.
   *
   * @return boolean
   *   TRUE if the callback can run on the given index; FALSE otherwise.
   */
  public function supportsIndex(SearchApiIndex $index) {
    if ($this
      ->isMultiEntityIndex($index)) {
      return in_array('node', $index->options['datasource']['types']);
    }
    return $index
      ->getEntityType() === 'node';
  }

  /**
   * Alter items before indexing.
   *
   * Items which are removed from the array won't be indexed, but will be marked
   * as clean for future indexing.
   *
   * @param array $items
   *   An array of items to be altered, keyed by item IDs.
   */
  public function alterItems(array &$items) {
    $multi_types = $this
      ->isMultiEntityIndex($this->index);
    foreach ($items as $id => $item) {
      $node = $item;
      if ($multi_types) {
        if ($item->item_type !== 'node') {
          continue;
        }
        $node = $item->node;
      }
      if (empty($node->status)) {
        unset($items[$id]);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SearchApiAbstractAlterCallback::$index protected property The index whose items will be altered.
SearchApiAbstractAlterCallback::$options protected property The configuration options for this callback, if it has any.
SearchApiAbstractAlterCallback::configurationForm public function Implements SearchApiAlterCallbackInterface::configurationForm(). Overrides SearchApiAlterCallbackInterface::configurationForm 6
SearchApiAbstractAlterCallback::configurationFormSubmit public function Implements SearchApiAlterCallbackInterface::configurationFormSubmit(). Overrides SearchApiAlterCallbackInterface::configurationFormSubmit 4
SearchApiAbstractAlterCallback::configurationFormValidate public function Implements SearchApiAlterCallbackInterface::configurationFormValidate(). Overrides SearchApiAlterCallbackInterface::configurationFormValidate 1
SearchApiAbstractAlterCallback::isMultiEntityIndex protected function Determines whether the given index contains multiple types of entities.
SearchApiAbstractAlterCallback::propertyInfo public function Implements SearchApiAlterCallbackInterface::propertyInfo(). Overrides SearchApiAlterCallbackInterface::propertyInfo 6
SearchApiAbstractAlterCallback::__construct public function Implements SearchApiAlterCallbackInterface::__construct(). Overrides SearchApiAlterCallbackInterface::__construct 1
SearchApiAlterNodeStatus::alterItems public function Alter items before indexing. Overrides SearchApiAlterCallbackInterface::alterItems
SearchApiAlterNodeStatus::supportsIndex public function Check whether this data-alter callback is applicable for a certain index. Overrides SearchApiAbstractAlterCallback::supportsIndex