I have content type feature
and i have field hit_count
in this c.type, also i have db table - hit_count
- example:
nid hit_count
1 434
2 233
3 512
I want to output hit_count
inside my field - hit_count
on current node(also should appear on node edit). So for example if node id is 1
, field hit_count = 434
, and if admin want to edit this field i want to update field value to my table hit_count
with current nid
and field value hit_count
.
To save value into my database table i will use hook_node_update
and just get fields nid
and hit_count
values and update my table.
But i don't know what hook
should i use or how to insert this value from database to my field. There are lots of nodes with content type feature
.
UPDATE
My first thought is - why do you use a separate db table for this rather than simply using an integer field in the content type?
Hit count
module was created long time ago, client wanted to disable/enable statistics for every content type, so default statistics
module does not fit our needs. And now client want to manage this hit counts
for certain nodes etc...
Also i managed to insert value to edit form on hook_exit
updated custom hit count module.
function hit_count_exit($destination = NULL) {
if ($node = menu_get_object()) {
$selected_types = array_filter(variable_get('hit_count_content_types', array()));
if (!empty($selected_types)) {
if (in_array($node->type, $selected_types)) {
db_update('node_hit_counter')
->expression('totalcount', 'totalcount + 1')
->condition('nid', $node->nid)
->execute();
if($node->type == 'feature') {
$val = db_query("SELECT * FROM {node_hit_counter} WHERE nid='$node->nid'")->fetchAll();
db_merge('field_data_field_hit_count_node')
->key(array('entity_id' => $node->nid))
->fields(array(
'entity_type' => 'node',
'bundle' => 'feature',
'deleted' => 0,
'entity_id' => $node->nid,
'revision_id' => $node->nid,
'language' => 'und',
'delta' => 0,
'field_hit_count_node_value' => $val[0]->totalcount,
))
->execute();
}
}
}
}
}
But right now i see next problem. I need to get rid of Drupal field cache, cuz i see cached value every time i reload page, and if i clear all caches i get current value of hit_count
.
drupal field cache
i need to get rid of it – Petro Popelyshko Mar 4 '13 at 15:20