2

I am using the feeds module to import an rss feed from twitter. The feed title and body starts with ": then my tweet". I wish to remover ":" from the creation of my nodes. I can remove it in the body by using a custom input format that removes it. However I can't remove it from the title.

I suppose I have two options:

  • While saving the nodes of my custom content type, remove the text
  • create a custom plugin for feeds

What do you think is the best way to do this? Should I try another way?

Update

I added hook_node_presave to deal with this. As it is called on both the insert and update.

/**
 * Implementation of hook hook_node_presave
 */
function my_module_node_presave($node) {
    if($node->type=='mytype'){
        $node->title =  _my_module_my_function($node->title);
        $node->body[$node->language][0]['value'] =  _my_module_my_function($node->body[$node->language][0]['value']);
    }
}

It works great but is this the correct place to be doing the check and removal?

2

I think this approach is fine for your use case, since it's so unlikely you'd intentionally begin a title or body with a colon on purpose.

I'd clean up the code a bit though for coding standards like

/**
 * Implements hook_node_presave().
 */
function my_module_node_presave($node) {
  if ($node->type == 'mytype') {
    $node->title = _my_module_my_function($node->title);
    $node->body[$node->language][0]['value'] =  _my_module_my_function($node->body[$node->language][0]['value']);
  }
}
0

Depending on what you are trying to do, the Feeds Tamper module might be a way to do simple modifications without having to write any code.

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.