When CCK is used to make a new content type and then images are added with img_assist to the body-field made with the CCK, the "real" body-field is left completely empty and the body content goes into another table field.
This results in img_assist_map on the database not getting updated at all, since the save/delete-functions on the module don't find any img_assist macros from the body-field.
Not sure if this is the exactly right way to inform about this fork, but here it goes :P
The fix I've done is pretty simple, only the img_assist_map_save() needs to be changed for the function to save the img IDs to the table correctly. This solution though works only if the body field made with CCK is named "body" (that makes the field be named field_body), so the work needed for this to be "good" update for lots of people, it would need to have a setting somewhere for the user to type in the field name..
For example if the user makes a new content type with CCK and makes fields "title" and "content", then the user would need to input the "content" into img_assist-settings for the field that he wants to get the image IDs to the img_assist_map. If he inputs "content", the field_body in the code below would just be changed to field_content.
The img_assist_map was desperately needed in our case, where we had to find the id of the image used in a node.
function img_assist_map_save($node) {
$macros = (array) img_assist_get_macros($node->body);
//START OF IMAGE_ASSIST.MODULE CHANGES
//UPDATE BY JARI LANA, 29.6.2006
//IF CCK IS USED TO SAVE THE BODY, THE $NODE->BODY WILL BE EMPTY, SO THE IMG_ASSIST MACROS
//WILL SHOULD BE SEARCHED FROM ANOTHER FIELD, IN THIS CASE field_body
if(empty($macros))
{
$cck_field_body = $node->field_body[0]['value'];
$macros = (array) img_assist_get_macros($cck_field_body);
}
// END OF IMG_ASSIST.MODULE CHANGES
db_query('DELETE FROM {img_assist_map} WHERE nid = %d', $node->nid);
//$macros = array_unique($macros); // No dups stored here.
static $nids = array();
foreach ($macros as $m) {
if (!isset($nids[$m['nid']])) {
db_query('INSERT INTO {img_assist_map} (nid, iid) VALUES(%d, %d)', $node->nid, $m['nid']);
$nids[$m['nid']] = $m['nid'];
}
}
}
Comments
Comment #1
RayZ commentedAre you saying that the img_assist tags currently only work on a body field? I assumed (and haven't had an opportunity to check) that img_assist works with any field that has input filtering enabled.
If this is the case, I think this is a bug*. And it requires a general fix that goes beyond the workaround provided.
* feel free to change the status back to feature request, if I've misunderstood
Comment #2
tormu commentedYep, that would change this custom patch useless and I guess it would work fine like that as you said, that it would take the images from any textarea that has the input filtering on :)
Comment #3
tormu commentedHere's another patch for the same problem.. In our case it was also needed to have the img_assistant to keep record of images in other fields than just body or something else - in multiple fields I mean.
This code here defines all the custom fields that the image macros will be searched and gathers them all into one array.
After that the array is checked for duplicates (makes it useless to have the unique-checking at the img_assist_get_macros() though) and then the database is updated as before.
As said earlier by RayZ, it would be optimal for the img_assistant to gather references of all the images in the node from all the textareas that can contain img macros, not just the body (or predefined fields with this modification).
Comment #4
karens commentedFirst of all, thanks so much for all the work that must have gone into this! I am just getting ready to add some of this functionality to some projects I'm working on (and was dreading it) and I was delighted to find that nearly everything I need, and a few things I didn't even think of, are already available and working pretty reliably. Nice job!
You really need a query to find the cck fields, since they can change at any time, and with cck you also need to allow for multiple values. I think the following snippet would do the job:
Comment #5
tormu commentedI'm not quite sure what those Global settings mean in that field, but as far as I see this alone isn't quite the solution yet..
I have a main_image and additional_images-fields besides teaser and body, and those seem to have a bit different global settings.
thus, the SQL in your patch returns only the teaser and the body.. It seems that the "Filtered text (user selects input format)" has to be on in order for the SQL to match.
However this code of yours does help a lot, do you know if there is anything wrong with just looping thru all the fields and not just the ones that have the "text_processing......" part? I'll try that tomorrow :)
Comment #6
karens commentedThe global settings code as written above will find cck text fields that have been defined to use filtered input. If you have any such fields, it should find them. You may be using some other kind of field instead of the cck text field. If so, we need to figure out how the field is stored in the database in order to search for it. Yes, you can look for all fields, but there really are only a couple that could possibly be using image_asst. Maybe you're using the imagefield?? I am not sure how it stores values, but I'll take a look when I get a chance. I was making the assumption you were using a cck text field.
Comment #7
tormu commentedYes, they are all CCK text fields as assumed, but only teaser and body have text formatting enabled. The main_image and additional_images are text fields as well but only plain text since img_assist macros are only content they are supposed to receive.
The img_assist-button appears on every textarea on the form and teaser, body and these image fields above are those. It's pretty odd that there's no type "textarea" and "textfield" on the database, so the main_image field that appears as a textarea is with same settings on the database as is for example my "imagesource"-field that is just a one line input element. Seems like the database hasn't got any differences between a -element (CCK textfield with over 1 line) and -element (CCK textfield with 1 line).
field_main_image: text, a:3:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";}
field_imagesource: text, a:3:{s:15:"text_processing";s:1:"0";s:10:"max_length";s:0:"";s:14:"allowed_values";s:0:"";}
Guess it'll work if I'll just put it to search every field that is type "text"..
Comment #8
darren ohWhat's the status on this? Does Img_assist not work for all textareas that allow filtered input? Sounds like a non-issue to me. Please re-open if you can explain why I am wrong.
Comment #9
tormu commentedI still don't see the img_assist_map updating - I introduced a new node type and there's a textarea that has the Img_assist-image/button below it to allow image macros included in that field, but the module itself doesn't save the information about what nodes have what image nodes in the database. Newest 4.7 version installed.
Comment #10
sunSupport for 4.7.x is discontinued. So, this won't fix for 4.7.x as long as you do not provide a patch.