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

JMOmandown’s picture

Status: Active » Closed (fixed)

This 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.