Warning: Undefined array key "HTTPS" in include() (line 29 of /opt/www/fdv2/drupal.stage/web/sites/default/settings.local.php).
include('/opt/www/fdv2/drupal.stage/web/sites/default/settings.local.php') (Line: 4)
require('/opt/www/fdv2/drupal.stage/web/sites/drupal001.net/settings.php') (Line: 145)
Drupal\Core\Site\Settings::initialize('/opt/www/fdv2/drupal.stage/web', 'sites/drupal001.net', Object) (Line: 1099)
Drupal\Core\DrupalKernel->initializeSettings(Object) (Line: 701)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
怎样在模块的install文件里面添加content type的field - Drupal大学 - Drupal问答论坛
首页 / 帖子
怎样在模块的install文件里面添加content type的field

怎样在模块的install文件里面添加content type的field?

2个答案
YOYO
发布于:2016-01-05 18:29

使用Drupal的 field_create_instance API,具体参考: 
http://www.espend.de/artikel/drupal-7-field-api-setup-new-content-type-install-and-add-fields.html 

王斌
发布于:2016-02-03 16:31
example:
    field_create_field(array(
      'field_name' => 'field1',
      'type' => 'text',
      'cardinality' => 1,
      'settings' => array(
        'max_length' => '255',
      ),
    ));
    field_create_instance(array(
      'field_name' => 'field_1',
      'entity_type' => $entity_type,
      'bundle' => 'key_contact',
      'label' => 'Mobile',
      'required' => FALSE,
      'widget' => array(
        'weight' => 4,
        'type' => 'text_textfield',
        'module' => 'text',
        'active' => 1,
        'settings' => array(
          'size' => 60
        )
      ),
      'settings' => array(
        'text_processing' => 0,
        'user_register_form' => FALSE
      ),
      'display' => array(
          'default'=>array(
              'label' => 'above',
              'type' => 'text_default',
              'module' => 'text',
              'weight' => 9
          )
      )
    ));