I would like to have the feature, that if users on my site post internal links within a text, this links are replaced by a thumbnail, node title etc. For choosing what to show instead of the link I would like to use Views. What would be the best method to do so?

  • I think, a simple replacement with hook_node_submit() or something, is not a good solution: If the user edits his content, I want him to see only what he added himself.
  • I could do it within the template, but this is not very elegant, I guess.
  • What is about hook_url_outbound_alter(), would that be the best way?

Please give me a hint.

  • 1
    this sounds more like an input filter to me, eg, substituting http://www.foo.com/bar/baz in text with a clickable link wrapped around whatever the main image is.
    – Jimajamma
    May 21 '13 at 22:47
  • users might post links to node body field or any textarea fields?
    – Aboodred1
    May 21 '13 at 22:52
  • Just in the body field.
    – user5950
    May 21 '13 at 22:58

The correct way to do this is to write text filter and add it to input formats your users will be using. Here you have Basic description of filters and formats - for Drupal 5 and 6, but concept is still valid. They are applied on display - Drupal agrees with you that you should save just what user wrote.

You need to use hook_filter_info(). Read about it, and then about rest of filter hooks family and you will have an idea.

To provide proper content for filter, well, there is no definitive solution. If users will only input node id, simple node_load is enough. Every set of scenarios and every use case calls for it own methods. Views are elastic tools, I guess for pretty big part of use cases they can be the tool.

  • The fastest replay I ever got. Thank you, that seems to be exactly what I was looking for!
    – user5950
    May 21 '13 at 22:57

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.