I am writing a plugin that sets up Craft in a particular way and have created a category field, but can't figure out how to assign a category group to the field, I have the following:
protected function createCategoriesField() {
// Get the field group
$group = (new \craft\db\Query())
->select("id")
->from("fieldgroups")
->where(["name" => "common"])
->one();
// Get the category group
$catGroup = Craft::$app->categories->getGroupByHandle("categories");
// Initialize the field
$field = new \craft\fields\Categories([
"groupId" => $group["id"],
"name" => "Categories",
"handle" => "categories",
"selectionLabel" => "Select categories",
"sources" => $catGroup
]);
// Save the field
return (Craft::$app->getFields()->saveField($field));
}
It seems sources is the correct setting, but it accepts 'source keys' which I'm unfamiliar with 🤔