public function Index::removeField in Search API 8
Removes a field from the index.
If the field doesn't exist, the call will fail silently.
Parameters
string $field_id: The ID of the field to remove.
Return value
$this
Throws
\Drupal\search_api\SearchApiException Thrown if the field is locked.
Overrides IndexInterface::removeField
2 calls to Index::removeField()
- Index::onDependencyRemoval in src/
Entity/ Index.php - Informs the entity that entities it depends on will be deleted.
- Index::preSave in src/
Entity/ Index.php - Acts on an entity before the presave hook is invoked.
File
- src/
Entity/ Index.php, line 730
Class
- Index
- Defines the search index configuration entity.
Namespace
Drupal\search_api\EntityCode
public function removeField($field_id) {
$field = $this
->getField($field_id);
if (!$field) {
return $this;
}
if ($field
->isIndexedLocked()) {
throw new SearchApiException("Cannot remove field with machine name '{$field_id}': field is locked.");
}
unset($this->fieldInstances[$field_id]);
return $this;
}