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

simple drupal 6 question, how to move Author and Date info at the bottom of the page
Redirecting or rewriting drupal links
Drupal 6: in hook_cron, how do I specify the path to a module file?
I Need Help Modifying CKEditor's Default Image Property Paths
Drupal 6 Faceted Search
How to send HTML email in drupal 6 using drupal_mail?
How to display some results from an external database in a drupal node?
need to pipe between menu items in drupal (non-css)
Drupal multisite setup
transferring drupal site from localhost to live server
drupal 6 : node.tpl.php $links variable, where to configure the content?
Drupal: Create menu item for a view
How to render block programmatically with standard theme
Login to drupal
Apache Solr search index problem
drupal database backup [closed]

Categories

HOME
image
atom-editor
single-sign-on
path-finding
smarty
plot
office365api
dot
xmpp
spring-cloud-stream
jxls
icloud
installshield
onelogin
ios-charts
medical
vb.net-2010
windows-phone-7
messages
iolanguage
opentracing
ab-testing
textfield
autocad-plugin
mps
accessor
wkwebview
format-specifiers
autosys
java-7
javacv
semantic-analysis
kannel
kendo-datasource
google-cloud-nl
flink-streaming
nat
bosh
stringtemplate
wpf-controls
wixsharp
ssjs
trim
gulp-sourcemaps
node-gyp
firebase-admin
user-accounts
domain-model
yii2-extension
nodebb
feeds
arrow-keys
hittest
google-cdn
nested-sets
spring-android
plottable.js
gstreamer-0.10
design-by-contract
browser-link
freedesktop.org
msys
cartesian-product
citrus-pay
iis-arr
generic-programming
oberon
jsonpickle
ng-animate
c3
nstableviewcell
document-classification
aapt
datagridviewcolumn
dotnetnuke-5
back-stack
eventlistener
drools-planner
android-hardware
referrer
mt
cisco-jtapi
armcc
ocx
online-compilation
gdlib
iphone-web-app
xfbml
html-input
google-friend-connect
digest-authentication
sortable-tables
routedevent
nhibernate.search
substrings
exchange-server-2003
noscript
text-coloring
mediarss

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App