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.
Hey, I am creating custom content type programmatically and was wondering if there was any way to programmatically assign the field instances to a field group I have already created?
Thanks
Comments
Comment #1
Ehud CreditAttribution: Ehud commentedSubscribing
Comment #2
ndeschildre CreditAttribution: ndeschildre commentedHello,
I just happened to search for it, and came up with this working bit of code:
Comment #3
acbramley CreditAttribution: acbramley commentedThanks @ndeschildre that worked great, think this should be closed now.
Comment #4
tariqinam CreditAttribution: tariqinam commentedHi,
Not sure how it worked for you. Because array key name must match with database field name. And They are:
| entity_type | varchar(32) | NO | | | |
| bundle | varchar(128) | NO | | | |
| mode | varchar(128) | NO | | | |
I have to use following format to get it working. let me know if i am doing something silly here.
$groups = field_group_read_groups(array(
'entity_type' => 'node',
'bundle' => 'bundle type',
'mode' => 'view_mode_name'));
Comment #5
srinivasraod CreditAttribution: srinivasraod commentedHi,
You can try with with this if you get an empty array....
$groups = field_group_read_groups();
$your_group = $groups['node']['article']['form']['group_your_group'];
$your_group->children[] = 'field_your_new_field';
field_group_group_save($your_group);