field_collection.inc 984 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * @file
  4. * Contains the CER plugin for Field Collection fields.
  5. */
  6. class CerFieldCollectionField extends CerField implements CerEntityContainerInterface {
  7. /**
  8. * Implements CerField::getTargetType().
  9. */
  10. public function getTargetType() {
  11. return 'field_collection_item';
  12. }
  13. /**
  14. * @override CerField::getTargetBundles().
  15. */
  16. public function getTargetBundles() {
  17. return array($this->name);
  18. }
  19. /**
  20. * Implements CerEntityContainerInterface::createInnerEntity().
  21. */
  22. public function createInnerEntity(EntityDrupalWrapper $owner) {
  23. // Create an empty field collection item.
  24. $collection = new EntityDrupalWrapper('field_collection_item', entity_create('field_collection_item', array('field_name' => $this->name)));
  25. $collection->host_entity->set( $owner );
  26. $collection->save(TRUE);
  27. // 'Reference' the newly created field collection item.
  28. $this->getHandler($owner)->add($collection);
  29. return $collection;
  30. }
  31. }