Custom filter with hook_filter_info() in Drupal -


i got problem when trying create custom filter hook_filter_info(). have make replacement based on fields of current viewed node. using following code.

return str_replace('%people1%', 'replacing working', $text); 

in process callback, code works fine, can't current node id (menu_get_item() or arg()). also, have clear cache every time make changes ('cache' => false).

is there need know processing data in process callback?

menu_get_item() , arg() don't return different value when called process callback of input filter; not returning value expecting, because input filter called in different context think.

an input filter called when:

  • a node body needs rendered
  • a comment body needs rendered
  • a entity field using input format needs rendered
  • a view created views module using input format render text entered user
  • a module using input format render text entered user

even in case input filter used render body of node, there still 2 cases:

  • the node rendered alone in page (e.g. http://example.com/node/2)
  • the page shows more 1 node (e.g. front page shows list of nodes promoted front page)

a module implementing input filter cannot understand entity called, , path of current page doesn't give information. example, have module @ mymodule/disclaimer shows content of node id equal 2, or have view @ example_path/just_to_make_an_example shows excerpt taken nodes matching criteria decided.

if need replace words in node body, example replacing %author% username of node creator, should rather implement hook_node_view_alter().


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -