我正在寻找一种在代码中创建有机组的方法。 在网络上,我找到了关于如何将节点添加到组等的manny资源,而不是如何自己创建组。
我使用drupal接口完成了它,但这不是很便携。我已经尝试使用功能模块,虽然我发现有很多问题。缺少字段等。
通过界面,您可以通过制作新的内容类型来创建群组,然后在“有机群组”标签下选择“群组”
我知道如何在代码中创建内容类型
$type = array(
'type' => 'Termbase2type',
'name' => t('Termbase2name'),
'base' => 'node_content',
'custom' => 1,
'modified' => 1,
'locked' => 0,
'title_label' => 'Termbase2',
'description' => 's a database consisting of concept-oriented terminological entries (or ‘concepts’) and related information, usually in multilingual format. Entries may include any of the following additional information: a definition; source or context of the term; subject area, domain, or industry; grammatical information (verb, noun, etc.); notes; usage label (figurative, American English, formal, etc.); author (‘created by’), creation/modification date (‘created/modified at’); verification status (‘verified’ or ‘approved’ terms), and an ID. A termbase allows for the systematic management of approved or verified terms and is a powerful tool for promoting consistency in terminology. *wiki',
'og_group_type' => 1,
'og_private' => 0,
'og_register' => 0,
'og_directory' => 0,
'og_selective' => 3,
);
$type = node_type_set_defaults($type);
node_type_save($type);
node_add_body_field($type);
但我找不到任何关于如何将内容类型设置为组的线索,因此它可以拥有组成员。
答案 0 :(得分:1)
这有效:
// get existing content types
$content_types = node_type_get_types();
$t = get_t();
// create the currency CT
$type_name = 'cc';
if (!array_key_exists($type_name, $content_types)) {
// Create the type definition array.
$type = array(
'type' => $type_name,
'name' => $t('Community Currency'),
'base' => 'node_content',
'description' => $t('A community that trades in a virtual currency.'),
'custom' => 1,
'modified' => 1,
'locked' => 0,
);
$type = node_type_set_defaults($type);
node_type_save($type);
// Add a body field.
node_add_body_field($type);
variable_set('og_group_type_' . $type_name, TRUE);
og_ui_node_type_save($type_name);
}
答案 1 :(得分:0)
一种选择是使用Drupal的drupal_form_submit() function到programmatically submit the necessary forms。它可能有点乏味,并不像使用API那么简单,但它应该可以工作。