[英]Creating Drupal 7 Field Groups Programmatically
我正在嘗試自動對由我的自定義模塊創建的字段進行分組,但它不太工作。 我的期望是將創建一個字段組並將現有字段分配給它。 我正在使用 Field Groups 模塊,因為它看起來非常標准。
正如http://drupal.org/node/1606758 上的建議,我已經使用 ctools 批量導出來生成代碼。 我已將以下代碼移動到我的模塊中。 不知道為什么這不起作用:
hook_field_group_info()
和hook_ctools_plugin_api()
都被擊中了; 正在記錄我添加的調試標志。我可能做錯了什么?
========== 來自 Ctools 批量導出器:===========
把它放在 nmc_directory.info
name = nmc_directory export module
description = Export objects from CTools
dependencies[] = field_group
package = Chaos tool suite
core = 7.x
把它放在 nmc_directory.module 中
<?php
/**
* Implements hook_ctools_plugin_api().
*/
function nmc_directory_ctools_plugin_api($module, $api) {
if ($module == 'field_group' && $api == 'field_group') {
return array('version' => 1);
}
}
把它放在 nmc_directory.field_group.inc
<?php
/**
* Implements hook_field_group_info().
*/
function nmc_directory_field_group_info() {
$field_groups = array();
$field_group = new stdClass();
$field_group->disabled = FALSE; /* Edit this to true to make a default field_group disabled initially */
$field_group->api_version = 1;
$field_group->identifier = 'group_dir_phys_consumer_info|node|dir_physicians|form';
$field_group->group_name = 'group_dir_phys_consumer_info';
$field_group->entity_type = 'node';
$field_group->bundle = 'dir_physicians';
$field_group->mode = 'form';
$field_group->parent_name = '';
$field_group->data = array(
'label' => 'Online Medical Providers Directory: Website (Consumer Information)',
'weight' => '0',
'children' => array(
0 => 'dir_phys_gender',
1 => 'dir_phys_category',
2 => 'dir_phys_title',
3 => 'dir_phys_fname',
4 => 'dir_phys_lname',
5 => 'dir_phys_suffix',
6 => 'dir_phys_medfield_1',
7 => 'dir_phys_medfield_2',
8 => 'dir_phys_phone_public',
),
'format_type' => 'fieldset',
'format_settings' => array(
'label' => 'Online Medical Providers Directory: Website (Consumer Information)',
'instance_settings' => array(
'required_fields' => 1,
'classes' => '',
'description' => '',
),
'formatter' => 'collapsed',
),
);
$field_groups['group_dir_phys_consumer_info|node|dir_physicians|form'] = $field_group;
return $field_groups;
}
供將來參考 - 此代碼(和方法)完美運行。
我的問題是這個模塊變得如此之大(4 個內容類型、60 多個字段、6 個詞匯表等),以至於它在我的本地主機上運行非常緩慢。 當我在我的臨時服務器上運行它時,它運行得非常好。 我在我的本地主機 php.ini 上增加了最大執行時間,現在它在本地也能正常工作。
FWIW:我能夠使用 /devel/reinstall(來自 Devel 模塊)重新安裝模塊比通過模塊管理頁面快一點。 不知道為什么這也沒有超時,但沒有。
編輯:嗯.. 幾天后,我不確定問題是否完全是由於 php 執行時間造成的。 這起到了一定的作用(某些字段從未創建過+還有其他問題),但是現在卸載並重新安裝我的模塊會產生與字段組有關的分散結果。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.