public function FieldCollection::getFieldCollectionItem in Field collection 8
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldType/FieldCollection.php \Drupal\field_collection\Plugin\Field\FieldType\FieldCollection::getFieldCollectionItem()
3 calls to FieldCollection::getFieldCollectionItem()
- FieldCollection::delete in src/
Plugin/ Field/ FieldType/ FieldCollection.php - Defines custom delete behavior for field values.
- FieldCollection::isEmpty in src/
Plugin/ Field/ FieldType/ FieldCollection.php - Determines whether the data structure is empty.
- FieldCollection::preSave in src/
Plugin/ Field/ FieldType/ FieldCollection.php - Care about removed field collection items.
File
- src/
Plugin/ Field/ FieldType/ FieldCollection.php, line 77
Class
- FieldCollection
- Plugin implementation of the 'field_collection' field type.
Namespace
Drupal\field_collection\Plugin\Field\FieldTypeCode
public function getFieldCollectionItem($create = FALSE) {
if (isset($this->field_collection_item)) {
return $this->field_collection_item;
}
elseif (isset($this->value)) {
// By default always load the default revision, so caches get used.
$field_collection_item = FieldCollectionItem::load($this->value);
if ($field_collection_item !== NULL && $field_collection_item
->getRevisionId() != $this->revision_id) {
// A non-default revision is a referenced, so load this one.
$field_collection_item = \Drupal::entityTypeManager()
->getStorage('field_collection_item')
->loadRevision($this->revision_id);
}
return $field_collection_item;
}
elseif ($create) {
$field_collection_item = FieldCollectionItem::create([
'field_name' => $this
->getFieldDefinition()
->getName(),
]);
// TODO: Uncomment or delete
/*
$field_collection_item->setHostEntity($this->getEntity(), FALSE);
*/
return $field_collection_item;
}
return FALSE;
}