You are here

public function FieldCollectionItem::getDelta in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/Entity/FieldCollectionItem.php \Drupal\field_collection\Entity\FieldCollectionItem::getDelta()

Returns the $delta of the reference to this field collection item.

Return value

int|null The $delta of the reference to this field collection item, or NULL if the reference doesn't exist in the host yet.

Overrides FieldCollectionItemInterface::getDelta

3 calls to FieldCollectionItem::getDelta()
FieldCollectionItem::deleteHostEntityReference in src/Entity/FieldCollectionItem.php
Deletes the host entity's reference of the field collection item.
FieldCollectionItem::label in src/Entity/FieldCollectionItem.php
Overrides \Drupal\Core\Entity\label().
FieldCollectionItem::save in src/Entity/FieldCollectionItem.php
Save the field collection item.

File

src/Entity/FieldCollectionItem.php, line 241

Class

FieldCollectionItem
Defines the field collection item entity class.

Namespace

Drupal\field_collection\Entity

Code

public function getDelta() {
  if (($host = $this
    ->getHost()) && isset($host->{$this
    ->bundle()})) {
    foreach ($host->{$this
      ->bundle()} as $delta => $item) {
      if (isset($item->value) && $item->value == $this
        ->id()) {
        return $delta;
      }
      elseif (isset($item->field_collection_item) && $item->field_collection_item === $this) {
        return $delta;
      }
    }
  }
}