2016-04-23 24 views
0

下面的代碼將在所有分類文本字段添加表單,但我想添加文本字段的具體分類標準「色」Drupal的7 - 通過編程對特定分類

if(!db_table_exists('field_data_field_moi_uc_oid')){ 
     $field = array(
     'field_name' => 'field_moi_uc_oid', 
     'type' => 'text', 
     'label' => t('Relates to option') 
    ); 
     field_create_field($field); 
    } 
    // Attach the field to our taxonomy entity 
    $instance = array(
     'field_name' => 'field_moi_uc_oid', 
     'entity_type' => 'taxonomy_term', 
     'bundle' => 'variant', 
     'label' => t('Relates to option'), 
     'description' => t('This is the description'), 
     'required' => true, 
     'widget' => array(
     'type' => 'text_textfield', 
     'settings'=> array(
      'max_width'=>80, 
     ) 
    ), 
    ); 
    field_create_instance($instance); 
+0

您目前正在將該字段應用於「變體」分類標準/分析包的分類術語。 'variant'是你的分類。顏色在哪裏進入? – 2pha

+0

變體是詞彙,這個詞彙包含兩個分類,顏色和大小。不同的領域需要爲這兩個分類創建 – Bharanikumar

+0

然後我對你的設置感到困惑。據我所知,分類術語被添加到詞彙表中。 – 2pha

回答

1

分類法在Drupal詞彙表中進行分組添加文本框。它可以是(顏色,標籤等) 然後每個Taxonomy詞彙都有術語(實際數據)。

上面的代碼創建一個領域到稱爲變異

$instance = array(
    'field_name' => 'field_moi_uc_oid', 
    'entity_type' => 'taxonomy_term', 
    // This is the vocabulary 
    'bundle' => 'variant', 
    'label' => t('Relates to option'), 
    'description' => t('This is the description'), 
    'required' => true, 
    'widget' => array(
    'type' => 'text_textfield', 
    'settings'=> array(
     'max_width'=>80, 
    ) 
), 
); 
field_create_instance($instance); 

一個單一的詞彙來使此代碼段創建一個字段,而不是對色彩的詞彙,然後只是改變這一行

'bundle' => 'color', 

記,我只能看到基於你所說的答案:)