Drupal 7 Drupal 7字段多值删除和显示

Drupal 7 Drupal 7字段多值删除和显示,drupal-7,field,Drupal 7,Field,我已经被困了好几天了,我希望有人能帮助我。 我正在编写一个模块来链接到不同的节点。我知道这样的模块确实存在,但是我想练习编写一个模块,我尝试查看其他模块以供参考,但是,我无法发现任何问题 添加模块后,我激活自定义节点类型中的字段,并选择“允许多值”。当我添加该内容类型的内容时,将显示字段的两个而不是一个,当我添加额外字段时,我无法删除。我希望有人能给我一些关于如何修复它的指导。我在下面附上了问题的截图。我还希望添加一个删除按钮/一种删除额外项目的方法。经过几天的研究,我找不到一个drupal方法

我已经被困了好几天了,我希望有人能帮助我。 我正在编写一个模块来链接到不同的节点。我知道这样的模块确实存在,但是我想练习编写一个模块,我尝试查看其他模块以供参考,但是,我无法发现任何问题

添加模块后,我激活自定义节点类型中的字段,并选择“允许多值”。当我添加该内容类型的内容时,将显示字段的两个而不是一个,当我添加额外字段时,我无法删除。我希望有人能给我一些关于如何修复它的指导。我在下面附上了问题的截图。我还希望添加一个删除按钮/一种删除额外项目的方法。经过几天的研究,我找不到一个drupal方法来做这件事

下面是我添加的代码供参考 对于alloy_to_relation.install,我添加了以下内容

function belong_to_relation_field_schema ($field) {
if ($field['type'] == 'belong_to_relation') {

// Declare fields in the db
$columns = array (
  'to_node_type' => array (
    'type' => 'varchar',
    'length' => '64',
    'not null' => FALSE,
    'description' => 'The relation id from the belong_to_relation table',
  ),
  'to_node_nid' => array (
    'type' => 'int',
    'not null' => FALSE,
    'description' => 'the node id of the to node',
  ),
  'extended_node_nid' => array (
    'type' => 'int',
    'not null' => FALSE,
    'description' => 'the node id of the extended field node',
  ),
);

return array (
  'columns' => $columns,
  'indexes' => array(),
);
  }

}
function belong_to_relation_field_info () {
return array (
'belong_to_relation_reference' => array (
  'label' => t("Belong to Relation Node Reference"),
  'description' => t('This field stores a node reference to a node of another content type'),
  'default_widget' => 'belong_to_relation_reference_widget',
  'default_formatter' => 'belong_to_relation_reference_formatter',
),
);
}

function belong_to_relation_field_widget_info () {
return array (
'belong_to_relation_reference_widget' => array (
  'label' => t('Default'),
  'field types' => array ('belong_to_relation_reference'),
),
  );
}

function belong_to_relation_field_widget_form (&$form, &$form_state, $field, 
                                                 $instance, $langcode, $items, 
                                                 $delta, $element) { 

$element += array(
    '#type' => 'fieldset',
    '#tree' => true
);     

$element['to_node_type'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['to_node_type']) ? $item['to_node_type'] : NULL,
'#empty_option' => 'Select a Node type',
);

$element['to_node_nid'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['to_node_nid']) ? $item['to_node_nid'] : NULL,
'#empty_option' => 'Select a Node',
);

$element['extended_node_nid'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['extended_node_nid']) ? $item['extended_node_nid'] : NULL,
'#empty_option' => 'Select a Node type',
);

return $element;
}

function belong_to_relation_field_is_empty ($item, $field) {
  return FALSE;
}

function belong_to_relation_field_formatter_info () {
    return array (
    'belong_to_relation_reference_formatter' => array (
        'label' => t('Simple Belong To Relation Formatter'),
        'field types' => array ('belong_to_relation_reference'),
    ),
);
}
对于Alloy_to_relation.module,我添加了以下内容

function belong_to_relation_field_schema ($field) {
if ($field['type'] == 'belong_to_relation') {

// Declare fields in the db
$columns = array (
  'to_node_type' => array (
    'type' => 'varchar',
    'length' => '64',
    'not null' => FALSE,
    'description' => 'The relation id from the belong_to_relation table',
  ),
  'to_node_nid' => array (
    'type' => 'int',
    'not null' => FALSE,
    'description' => 'the node id of the to node',
  ),
  'extended_node_nid' => array (
    'type' => 'int',
    'not null' => FALSE,
    'description' => 'the node id of the extended field node',
  ),
);

return array (
  'columns' => $columns,
  'indexes' => array(),
);
  }

}
function belong_to_relation_field_info () {
return array (
'belong_to_relation_reference' => array (
  'label' => t("Belong to Relation Node Reference"),
  'description' => t('This field stores a node reference to a node of another content type'),
  'default_widget' => 'belong_to_relation_reference_widget',
  'default_formatter' => 'belong_to_relation_reference_formatter',
),
);
}

function belong_to_relation_field_widget_info () {
return array (
'belong_to_relation_reference_widget' => array (
  'label' => t('Default'),
  'field types' => array ('belong_to_relation_reference'),
),
  );
}

function belong_to_relation_field_widget_form (&$form, &$form_state, $field, 
                                                 $instance, $langcode, $items, 
                                                 $delta, $element) { 

$element += array(
    '#type' => 'fieldset',
    '#tree' => true
);     

$element['to_node_type'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['to_node_type']) ? $item['to_node_type'] : NULL,
'#empty_option' => 'Select a Node type',
);

$element['to_node_nid'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['to_node_nid']) ? $item['to_node_nid'] : NULL,
'#empty_option' => 'Select a Node',
);

$element['extended_node_nid'] = array (
'#type' => 'select',
'#title' => t('Target Node Type'),
'#options' => array(),
'#default_value' => isset($item['extended_node_nid']) ? $item['extended_node_nid'] : NULL,
'#empty_option' => 'Select a Node type',
);

return $element;
}

function belong_to_relation_field_is_empty ($item, $field) {
  return FALSE;
}

function belong_to_relation_field_formatter_info () {
    return array (
    'belong_to_relation_reference_formatter' => array (
        'label' => t('Simple Belong To Relation Formatter'),
        'field types' => array ('belong_to_relation_reference'),
    ),
);
}
我目前正在MAMP上运行drupal 7.7。

OP写道:


已解决,需要删除。安装中的if$字段['type']=='allown\u to\u relation'行


已解决,需要删除中的if$字段['type']=='allown\u to\u relation'行。您可以将自己的答案作为此问题的接受答案发布。看见