【问题标题】:Create organic group programmatically以编程方式创建有机组
【发布时间】:2014-01-31 12:31:50
【问题描述】:

我正在寻找一种在代码中创建有机组的方法。 在网上我找到了很多关于如何将节点添加到组等的资源,但没有找到如何创建组本身。

我已经使用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);

但我找不到任何关于如何将内容类型设置为组的线索,因此它可以有组成员。

【问题讨论】:

  • 告诉我你解决了这个问题。我正在看这个。我认为开发模块会很有启发性?
  • 不,最后我为我的特定需求编写了一些代码,忽略了 OG 模块。

标签: drupal-7 organic-groups


【解决方案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);
}

【讨论】:

    【解决方案2】:

    一种选择是使用 Drupal 的 drupal_form_submit() functionprogrammatically submit the necessary forms。它可能有点乏味,并且不像使用 API 那样简单,但它应该可以工作。

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 1970-01-01
      • 2015-02-25
      • 2015-08-30
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 2013-03-28
      • 2013-07-25
      相关资源
      最近更新 更多