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.
So I am trying to create a field group dynamically through direct php. The issue is no matter the input values, the creation always results in a PDO exception for a duplicate entry.
<?php
module_load_include('module', 'ctools');
ctools_include('export');
$new_group = (object) array(
'identifier' => 'group_aircraft_10|commerce_order|commerce_order|form',
'group_name' => 'group_test',
'entity_type' => 'commerce_order',
'bundle' => 'commerce_order',
'mode' => 'form',
'children' => array(),
'parent_name' => '',
'weight' => 1,
'label' => 'Test Group',
'format_type' => 'div',
'disabled' => FALSE,
);
// Save and enable it in ctools
ctools_export_crud_save('field_group', $new_group);
ctools_export_crud_enable('field_group', $new_group->identifier);
?>
Comments
Comment #1
JMOmandown CreditAttribution: JMOmandown commentedThis was a result of trying to save then enable the identifier. When enabling the group is automatically saved, so the call to crud_save is unneeded. Removing it fixes the issue.