开发者

Drupal 7 Field Multiple value deletion and display

I have been stuck for days and I hope that somebody could help me out. I am writing a module to link to different node (I understand that such module does exist however I would like to practice coding a module, I did tried to look at other module for reference, however, I cannot spot any problem).

After I added the module, I activate the field in a custom node type and select allow multiple value. When I added the content (of that content type) two of the field appears instead of one, and when I added extra field, I cannot delete. I hope that someone can give me some direction on how to fix it. I have included a screenshot of the problem below. I am also hoping to add a delete button / a way to delete an extra item. After research for days, I cannot find a drupal way to do it.

Below are the code I added for reference for belong_to_relation.install, I added the following

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(),
);
  }

}

For belong_to_relation.module, I added the following

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'),
    ),
);
}

I am开发者_高级运维 currently running on drupal 7.7 on MAMP.


The OP wrote:

Solved, need to delete the if ($field['type'] == 'belong_to_relation') line in .install

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜