Removing [nid:n] in nodereference autocomplete

前端 未结 6 1395
难免孤独
难免孤独 2021-01-31 00:21

Using the autocomplete field for a cck nodereference always displays the node id as a cryptic bracketed extension:

Page Title [nid:23]

I unders

6条回答
  •  不要未来只要你来
    2021-01-31 00:57

    Ultimately, you need to change the output of nodereference_autocomplete() in nodereference.module.

    To do this properly, you want a custom module to cleanly override the function.

    This function is defined as a menu callback, thus,

    /**
     * Implementation of hook_menu_alter().
     */
    function custom_module_menu_alter(&$items) {
      $items['nodereference/autocomplete']['page callback'] = 'custom_module_new_nodereference_autocomplete';
    }
    

    Then, copy the nodereference_autocomplete function into your custom module, changing it's name to match your callback. Then change this one line:

    $matches[$row['title'] ." [nid:$id]"] = '
    '. $row['rendered'] . '
    ';

    Dropping the nid reference.

    $matches[$row['title']] = '
    '. $row['rendered'] . '
    ';

    I believe the identifier is purely cosmetic at this point, which means you could also change the text however you like. If it is not purely cosmetic, well, I haven't tested to see what will happen in the wrong conditions.

    I always meant to identify how to do this. Thank you for motivating me with your question.

提交回复
热议问题