如何以编程方式为内容类型创建字段,并将其添加到内容类型表单中
假设我有此字段“ map_description”。我知道我会使用此函数来定义字段: $field = array( 'field_name' => 'map_description', 'cardinality' => 1, 'type' => 'text', ); field_create_field($field); 我有这个代码,我不确定它会做什么,但是我被告知我将需要它: $instance = array( 'field_name' => 'map_description', 'label' => 'The map description.', 'bundle' => 'my_content_type', 'entity_type' => 'node', 'widget' => array( 'type' => 'text_textfield', ); field_create_instance($instance) 这两个代码位都在我的安装挂钩中,并且在我安装模块时运行。但是,尽管实际上创建了字段,但我必须通过“管理字段”将它们手动分配给内容类型,有没有办法自动将字段分配给内容类型?