You are here

public function Item::__clone in Search API 8

Implements the magic __clone() method to implement a deep clone.

File

src/Item/Item.php, line 465

Class

Item
Provides a default implementation for a search item.

Namespace

Drupal\search_api\Item

Code

public function __clone() {

  // The fields definitely need to be cloned. For the extra data its hard (or,
  // rather, impossible) to tell, but we opt for cloning objects there, too,
  // to be on the (hopefully) safer side. (Ideas for later: introduce an
  // interface that tells us to not clone the data object; or check whether
  // its an entity; or introduce some other system to override this default.)
  foreach ($this->fields as $field_id => $field) {
    $this->fields[$field_id] = clone $field;
  }
  foreach ($this->extraData as $key => $data) {
    if (is_object($data)) {
      $this->extraData[$key] = clone $data;
    }
  }
}