public function Field::setIndex in Search API 8
Returns the index of this field.
This is useful when retrieving fields from cache, to have the index always set to the same object that is returning them. The method shouldn't be used in any other case.
Parameters
\Drupal\search_api\IndexInterface $index: The index to which this field belongs.
Return value
$this
Throws
\InvalidArgumentException Thrown if the ID of the given index is not the same as the ID of the index that was set up to now.
Overrides FieldInterface::setIndex
File
- src/
Item/ Field.php, line 256
Class
- Field
- Represents a field on a search item that can be indexed.
Namespace
Drupal\search_api\ItemCode
public function setIndex(IndexInterface $index) {
$current_index_id = $this->index ? $this->index
->id() : $this->indexId;
if ($current_index_id !== NULL && $current_index_id != $index
->id()) {
throw new \InvalidArgumentException('Attempted to change the index of a field object.');
}
$this->index = $index;
$this->indexId = NULL;
$this->datasource = NULL;
return $this;
}