以编程方式创建有机组
问题描述:
我正在寻找一种在代码中创建有机组的方法。 在网络上,我发现曼尼资源如何将节点添加到组等,但不是如何创建一个组本身。以编程方式创建有机组
我已经使用drupal界面做了它,但这不是很便携。我尝试过使用功能模块,但我发现有很多问题。缺少字段等
通过该接口您可以通过制作新的contentType创建一个组,然后将标签下的“有机基团”您选择“组”
我知道如何在代码中创建
的内容类型$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);
但我找不到任何线索如何将内容类型设置为一个组,因此它可以有组成员。
答
一个选择是使用Drupal的drupal_form_submit() function到programmatically submit the necessary forms。它可能有点繁琐,不像使用API那样简单,但它应该可以工作。
答
这工作:
// 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);
}
告诉我你解决了这一..我看这个现在。我在想开发模块会有启发性吗? – Grizly
不,最后我最终为我的特定需求写了一些代码,忽略了OG模块。 – user3257301