Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi.
I am trying to create new field collection and attach it to content type and not the node.
Is it something that is possible?
$values = 'array of whatever';
$fr = 'newcollection';
$content_type = 'demoContent';
$field_entity = entity_create('field_'.$fr, $values);
$field_entity->setHostEntity($content_type, 'content_type'); #HELP!!! SOS!!! ...---...
$field_entity->save();
Comments
Comment #1
kalki2013 CreditAttribution: kalki2013 commentedComment #2
jmuzz CreditAttribution: jmuzz commentedI take it you are trying to define a new field in your content type that refers to your field collection bundle. You can't do it by creating an instance of the field collection bundle and setting it's host to the content type. Here is a thread that might be helpful:
http://drupal.stackexchange.com/questions/8284/programmatically-create-f...
You can't really accomplish anything by trying to set the host of a field collection item to a content type, so if your goal isn't to define a field on that content type, then please specify what you are trying to do.