- Issue created by @fkelly
- πΊπΈUnited States fkelly
Received the following in email. December 8, 2024
I am moving a website from Drupal 7 to Drupal 10.
I have a form where I add an image to the front of a Juicebox gallery (taking only the first 42 images) in a node with the following old code:
$imageinfo = image_get_info($newfile->uri);$newimage = array(
'fid' => $newfile->fid,
'uid' => $newfile->uid,
'filename' => $newfile->filename,
'uri' => $newfile->uri,
'filemime' => $newfile->filemime,
'filesize' => $newfile->filesize,
'status' => $newfile->status,
'timestamp' => $newfile->timestamp,
'rdf_mapping' => Array(),
'alt' => $form_state['values']['user_name'],
'title' => $form_state['values']['title'],
'width' => $imageinfo['width'],
'height' => $imageinfo['height']
);$update_node = node_load(278);
array_unshift($update_node->field_picture['und'], $newimage);
$update_node->field_picture['und'] = array_slice($update_node->field_picture['und'], 0, 42);
node_save($update_node);I wrote the code over 10 years ago. I can't work out where to find the equivalent information to update the code. I have successfully installed the Juicebox module and have a working gallery on a node of the test site and a form that uploads an image file, but that's about it.
Can you help?
With best wishes and very many thanks,
Jane"
Requests need to be put in the issue queue.
It is not clear from this request what needs to be done. Images that are displayed in a gallery are listed in an XML file, which in turn is embedded in a content type item. A Juicebox javascript program which you have linked to the Juicebox module code in turn processes this xml file and displays a gallery. There is a lot of documentation for this process in the Juicebox "project" on Drupal.org (where you are viewing this post). "Normally" and most reliably, the list of gallery items is kept in an xml file which is produced on your computer using the JuiceboxBuilder program. Instructions for this are in the project too. Support for the JuiceboxBuilder program has been moved around (it has always been "outside" of Drupal) several times. Support for JuiceboxBuilder in turn depends on code originally developed by Adobe (Adobe Air). I'm not sure what the status of that is.
Here is the first few lines from a sample xml file:
<?xml version="1.0" encoding="UTF-8"?> <juiceboxgallery enableAutoPlay="true" autoPlayOnLoad="true" > <image imageURL="images/001.jpg" thumbURL="thumbs/001.jpg" linkURL="images/001.jpg" linkTarget="_blank" sourcePath="D:\Pictures\2009 to 2010 pics including at sharis\001.jpg"> <title><![CDATA[001]]></title> <caption><![CDATA[]]></caption> </image> <image imageURL="images/002.jpg" thumbURL="thumbs/002.jpg" linkURL="images/002.jpg" linkTarget="_blank" sourcePath="D:\Pictures\2009 to 2010 pics including at sharis\002.jpg">
The imageurl, thumburl are really the key fields ... the sourcepath doesn't matter and will be different depending on where your site is located (hosting, local site etc.).
Theoretically, you could edit the xml file and add images "manually". That process might be "fraught" as we say.
But it could be that is not what you are after. I can't tell from your email.
Even though I'm personally listed as a maintainer, I am concentrating my efforts at finding a different way to do photo galleries ... different from Drupal. I spent yesterday morning seeing if I could use Google photos for this purpose. The galleries themselves work okay, however the PH.D computer scientists at Google have totally screwed up the way captions work ... or I should say don't work. I can link a working Google photo gallery to an article content type on Drupal and view it okay ... but without captions. This is a show stopper, at least until I find a work around.
I have looked at alternatives in the contrib module area of Drupal. None of them are well maintained or ready for prime time, IMHO.
Maintaining contrib modules here is difficult. The ground is constantly shifting under a contrib maintainer's feet. Code that worked fine gets deprecated and needs to be modified, tested and set up for users to download. The testing process itself changed radically from Drupal 10 to Drupal 11.
If I find a reliable alternative I'll post it here. You can see a work in progress at:
https://www.drupal.org/project/vvjs β
and some testing I am doing there. It is not ready for prime time either but it is a much simpler approach than Juicebox without the "extended" mess of dependencies inherent in Juicebox.
I was the person who sent the original email. Apologies for writing directly to you Frank, rather than posting here. The following code snippet recreates the functionality that I was asking for. The new setup in the Drupal Juicebox module leverages the functionality of managed files and stores fewer properties in the node. I successfully used this code as part of a custom module to add photos to a gallery via a Drupal form page.
$uri=$file->getFileUri(); $image_info = getimagesize(\Drupal::service('file_system')->realpath($uri)); $width=$image_info[0]; $height=$image_info[1]; $id=$file->id(); $update_node = Node::load(278); if ($update_node) { $newimage = [ 'target_id' => $id, 'alt' => $name, 'title' => $title, 'width' => $width, 'height' => $height, ]; $existing_images = $update_node->get('field_image')->getValue(); array_unshift($existing_images, $newimage); $existing_images = array_slice($existing_images, 0, 42); $update_node->set('field_image', $existing_images); $update_node->save(); }
- πΊπΈUnited States luke.leber Pennsylvania
Hi Jane, that looks right for working with the Entity API in Drupal 8+. Thanks for sharing!
Automatically closed - issue fixed for 2 weeks with no activity.