drupal-6


hook_comment is not working for update operation in drupal


I am trying to modify comment body before saving or updating in drupal 6. I am trying to use following code:
function mymodule_comment(&$a1, $op) {
switch ($op) {
case 'insert':
case 'update':
$a1['comment'] = myfunction($a1['comment']);
break;
}
}
But it is not updating the comment body after save. I also tried following code and it works:
function mymodule_comment(&$a1, $op) {
switch ($op) {
case 'insert':
$a1['comment'] = myfunction($a1['comment']);
comment_save($a1);
break;
}
}
But in case of update it is showing error:
function mymodule_comment(&$a1, $op) {
switch ($op) {
case 'update':
$a1['comment'] = myfunction($a1['comment']);
comment_save($a1);
break;
}
}
Any idea or help is very appreciated.
Ok I got the work around. first create a hook_form_alter function:
mymodule_form_alter($form,$form_state,$form_id){
if ($form_id == 'comment_form') {
$form['#submit'][] = 'mymodule_comment_form_submit';
}
}
Then create hook_comment_form_submit function and do your modification:
mymodule_comment_form_submit($form, $form_state){
$form_state['values']['comment'] = myfunciton($form_state['values']);
comment_save($form_state['values']);
}
I dont know whether it is a good idea or not but I found few of post in which this approach is used.

Related Links

Declaring function in Blocks in Drupal 6
How to add additional SUBMIT handler when a FILE is uploaded on Drupal
How to display all taxonomy terms as tree view in block drupal 6?
Drupal 6 not loading page-user.tpl.php file
Not able to add fields to my content type in Drupal 6
How do i overwrite the default drupal6 block template?
how to add a sum field in a view?
How can Block direct access to drupal 6 site
how to clear varnish cache for a drupal view?
Drupal 6- 404 is not showing for menu item URL pattern implemented using hook_menu
hook the function in module in drupal
Conditional Field is not working with content_multigroup, cck , drupal
In drupal Primary Link is like empty
Programmatically creating nodes with audiofield in Drupal 6
Drupal: How do I pass profile tokens to user profile page?
CKeditor stopped working after drush up (6.22 -> 6.25)

Categories

HOME
cakephp
twitter
image
clips
mockito
grep
sd-card
filtering
google-oauth
react-redux
binary-tree
fingerprint
adobe-analytics
reveal.js
timeout
remote-access
windows-server-2012
worldwind
ghc
graphlab
scichart
intentfilter
devops
chromebook
wpfdatagrid
instant-messaging
directx-10
scorm2004
fog
lxd
windows-dev-center
android-kernel
wixsharp
simplexml
swisscomdev
web-mining
android-browser
theano.scan
trim
segment
rainbowtable
jedis
veracode
tropo
nativeapplication
worker-thread
libusb-win32
akka-cluster
synchronous
objective-c-swift-bridge
word-vba-mac
time-and-attendance
nxt
grails-tomcat-plugin
phishing
qgraphicsview
phpcas
cartesian-product
content-length
map-projections
drawbitmap
fluid-dynamics
unity3d-gui
clicktag
google-reader
wp-query
jboss-weld
concurrent-collections
viadeo
multiprocessor
tidy
gridcontrol
smtp-auth
e4x
rdoc
coderush
getmessage
nsmanagedobject
netbeans-6.9
cinema-4d
xtype
propagation
lpeg
zend-translate
preference
fixed-width
kdbg
data-driven
mtj
sustainable-pace
noscript
putchar

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App