Field collection can be used in case a field has sub-fields. For e.g Name can have sub-fields such as First Name, Middle Name, and Last Name. There might be a requirement of loading field collection items programmatically. It can be done in following way:
$fieldCollection = \Drupal\field_collection\Entity\FieldCollectionItem::load($fieldCollectionId);
$firstName = $fieldCollection->get('field_first_name')->getValue();
It is better to use Paragraph module instead of using field collection, because it has better features and is being well maintained.
No comments:
Post a Comment