Can anyone suggest on how to programatically save fields to a GlobalSet? I’ve been following this: Programatically Adding Fields to a Layout
But, doesn’t seem to work with a global?
I am doing the following :
- Create a new field group - works
- Assign fields to field group - works
- Create global set - works
- Create field layout - works
- Create field layout tab - works
- Set fields to layout tab - nope
.
// get all the fields from company info fieldgroup
$Fields = $FieldGroup->getFields();
// Get field layout
$GlobalSetLayout = $GlobalSet->getFieldLayout();
// Create tab model
$GlobalSetLayoutTab = new FieldLayoutTabModel();
$layout = craft()->fields->getLayoutByType(ElementType::GlobalSet);
$GlobalSetLayoutTab->setLayout($layout);
$GlobalSetLayoutTab->setFields($Fields);
// Set the tab's fields
$GlobalSetLayoutTab->setFields($fields);
// setTabs() expects an array
$layoutTabs[] = $GlobalSetLayoutTab;
// Now, set the tabs back in the layout.
$layout->setTabs($layoutTabs);
Not sure if part of the issue is because Globals don’t exactly have a “tab”, but looking at others in the database it does seem to have one with the name “Content”