2

I have a content type with a Link field which allows an Unlimited number of values. However, it appears there is no way to Remove values like there is on an Image field with multiple values.

enter image description here

With an Image field, there are Remove buttons next to each item so that I can remove them:

enter image description here

Any idea why the Link field doesn't have a Remove button? I'm logged in as user #1 (an administrator) and just to be sure I've double checked that I have all permissions and such.

Any ideas?

1
  • You are right Kenny ..this is missing in link module as i have experienced the same. One thing what you can do to write custom code and delete query.
    – Rishi
    Aug 9 '12 at 6:39
3

It's perhaps not that obvious but all you need to do is empty the text field containing the value you want to remove. Once you save the entity the value will be gone.

Files need a remove button as there's no other way to 'empty' that particular field (a round-trip to the server is required to purge the file that was temporarily uploaded). Other, less complex fields (like text fields), don't need to contact the server via Ajax to do that, so I guess the remove button is deemed unnecessary.

If you're interested in the mechanics of this, have a look at the hook_field_is_empty function, which all field modules are required to implement.

3
  • Hm, it is removing some of the empty fields, but not all of them. I added 5 empty fields and saved, then re-edited and it still shows one of the empty fields. Hm. Aug 9 '12 at 17:22
  • That empty field is added automatically by the field system, so that there's always a new one available for the user to add to (it's just a UX thing). If you have a look in the database when you save the node there should only be one value for that field
    – Clive
    Aug 9 '12 at 17:28
  • It's an UX bug, though. See drupal.org/node/1038316 and the unlimited field remove module drupal.org/sandbox/daggerhart/1363702 Apr 18 '13 at 15:59
0

Don't know is the most straight snippet in the world, but this in a custom module is doing what I ask him to do:

<? php
/**
 * Implements hook_node_update().
 *
 * Delete the node's link field when the title is empty and the url is not
 * for every field of type link in this node
 */
function link_field_update_node_update($node) {
        if($node->type == 'top_menu_item' || $node->type == 'normal_web_content' ||
                        $node->type == 'schools') {

            if(!empty($node->field_link_1['und'])) {
                if($node->field_link_1['und'][0]['title'] == '' && 
                            $node->field_link_1['und'][0]['url'] !== '') {

              db_delete('field_data_field_link_1')
                ->condition('entity_id', $node->nid)
                ->execute();

        drupal_set_message(t('The value of the link1 field for @node was deleted',
                                 array('@node' => $node->title)));
                }
            }

          if(!empty($node->field_link_2['und'])) {
              if(isset($node->field_link_2) && $node->field_link_2['und'][0]['title'] == '' && 
                            $node->field_link_2['und'][0]['url'] !== '') {

              db_delete('field_data_field_link_2')
                ->condition('entity_id', $node->nid)
                ->execute();

        drupal_set_message(t('The value of the link2 field for @node was deleted',
                             array('@node' => $node->title)));
              }
            }

        }
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.