Drupal 7 field cache problems
Hello, I am working on a element and am having a lot of problems.
I have a form which has a hidden custom element on it. The element is basically a hidden status, which I am using to read to perform other functions. When the form is initially opened, the field defaults to "Not in Review".
After save, I have other code which appropriately changes the value in the table to "In Review" using the following code within a function.
db_update('field_data_field_proj_status')
->fields(array( 'field_proj_status_project_status_value' => 'In Review'))
->condition('entity_id', $nid)
->execute();
I can double check the database directly and the field appropriately says "In Review"
However, when I load the content page again (view) the field says "Not in Review". Then when I "Edit and Save" it automatically changes it again to "Not in Review".
I think this is happening because the content seems to be caching on the user side.
If I perform the same procedures by Creating content and checking database to confirm value was appropriately changed to "In Review" that works. Then if I hit "Empty Cache" button, the cache clears. Then if I view the content it appropriately says "In Review" and if I edit and save, the value never changes to "Not in Review".
So I know this is a cache problem.
Does anyone know code that I can use which will not cache a specific field? Or how I can prevent this problem?
Basically I need a field which I can change automatically after save. Then if it is edited and saved again, I cannot have it revert back to the original status.
Here is the code of how I am building the element through the custom form.module file within the widget.form
$element['project_status_value'] = array(
'#type' => 'hidden',
'#title' => t('Project Status:'),
'#default_value' => isset($items[$delta]['project_status_value']) ? $items[$delta]['project_status_value'] : 'Not in Review',
);
Thanks in advance
Hey Jen!
I don't have any ideas for you right now since it's not something I've been working on recently, but if I get a chance to dive in, I'll be sure to post back here and also send you a quick email.
Cheers!
Chris
Hi there,
It looks like this field is part of a node, in which case you would probably want to use node_save() after loading with node_load() and making adjustments, instead of using the Database API. This will trigger the kind of actions that take place behind the scenes when you do something like submit the node edit form.
Let me know if this points you in the right direction.
Cheers!
Chris