【问题标题】:Creating field group in installation profile在安装配置文件中创建字段组
【发布时间】:2013-10-31 12:03:05
【问题描述】:

在 Drupal 中,我希望我的附件字段位于垂直选项卡中。我已经取得了一些进展。我有以下代码:

$field_group = new stdClass();
$field_group->disabled = FALSE; 
$field_group->api_version = 1;
$field_group->identifier = 'group_test|node|foo|form';
$field_group->group_name = 'group_test';
$field_group->entity_type = 'node';
$field_group->bundle = 'foo';
$field_group->mode = 'form';
$field_group->parent_name = '';
$field_group->data = array(
    'label' => 'Test group',
    'weight' => '43',
    'children' => array(),
    'format_type' => 'tab',
    'format_settings' => array(
        'formatter' => 'closed',
        'instance_settings' => array(
            'description' => '',
            'classes' => 'group-test field-group-tab',
            'required_fields' => 1,
        ),
    ),
);

field_group_group_save($field_group);

这在 Drupal 中添加了一个字段组,现在唯一的问题是没有导入数据值(带有设置的数组)。所以我有一个没有数据的字段组。

据您所知,我使用“ctools bulk exporter”获得了部分代码。

关于如何编辑代码以便同时导入我的设置的任何想法?

【问题讨论】:

    标签: drupal installation drupal-7 field


    【解决方案1】:

    在 D7 中,我的 $field_group 对象中没有“数据”成员。您的“数据”成员下的每个元素都应直接位于 field_group 下。以稍微不同的格式(为自己节省一些打字时间),我这样做:

    $group = (object) array(
      'identifier' => 'group_userprofile_vendor2|user|user|form',
      'group_name' => 'group_userprofile_vendor2',
      'entity_type' => 'user',
      'bundle' => 'user',
      'mode' => 'form',
      'label' => 'Vendor Info',
      'children' => array(),
      'weight' => '300',
      'format_type' => 'tab',
      'format_settings' => array(
        'formatter' => 'closed',
        'instance_settings' => array(
          'description' => '',
          'classes' => '',
          'required_fields' => 1,
        ),
      ),
    );
    field_group_group_save($group);
    

    另外,如here 所述,如果您已经添加了一次组,如果您再次尝试添加该组,则会引发错误。我实际上已经测试了上面的代码,然后通过 UI 删除了该组,但是当我再次尝试时它仍然抛出错误。我最后不得不更改 group_name(因此上面的名称后面的 '2')让它再次运行。因此,您可能希望在调试期间观看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多