2014-01-31 5 views
4

Я ищу способ создания органической группы в коде. В Интернете я нахожу мужественные ресурсы о том, как добавить узел в группу и т. Д., Но не как создать группу.Создать органическую группу программно

Я сделал это, используя интерфейс 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); 

но я не могу найти ни малейшего понятия о том, как установить тип содержимого как группу, поэтому он может иметь членов группы.

+1

Скажи мне, что ты решил этот .. Я смотрю на это прямо сейчас. Я думаю, что модуль devel будет просвещен? – Grizly

+0

Нет, в конце концов, я заканчиваю написание некоторого кода для моих конкретных потребностей, игнорируя модули OG. – user3257301

ответ

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); 
} 
Смежные вопросы