$optionGroup = new CRM_Core_OptionGroup(); $optionGroup->name = 'my_option_group'; $optionGroup->title = 'My Option Group'; $optionGroup->is_reserved = 1; $optionGroup->is_active = 1; $optionGroup->save();
$optionGroup = CRM_Core_OptionGroup::getValue('my_option_group'); $optionValue = new CRM_Core_OptionValue(); $optionValue->option_group_id = $optionGroup->id; $optionValue->name = 'option_name'; $optionValue->label = 'Option Label'; $optionValue->is_reserved = 1; $optionValue->is_active = 1; $optionValue->weight = 1; $optionValue->save();In the first example, we create a new option group with the name 'my_option_group' and title 'My Option Group'. We also set the options to be reserved and active, and then save it to the database. In the second example, we retrieve the option group we created in the first example, then we create a new option for this group with a name of 'option_name' and label 'Option Label'. We also set the options to be reserved and active and give this option a weight of 1. Finally, we save the option value to the database. In conclusion, CRM_Core_OptionGroup class helps manage option groups and provides predefined values for fields in the CRM database.