Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Image Browser 2 allows developers to initiate an Image Browser pop-up window and then capture data via JSON when a user selects an image to insert. Integration requires three key parts:
This example module is called my_module.
1. Plug-in function
function my_module_imagebrowserapi($op) {
switch ($op) {
case 'load':
return array(
'url' => drupal_get_path('module', 'my_module') .'/my_module.js',
);
break;
}
}
2. Javascript file
// $Id$
/**
* @file my_module.js
*
* Javascript plugin for Image Browser.
*
* Variables:
* - data.fid [File ID]
* - data.preset [ImageCache preset name]
* - data.link_preset [ImageCache preset name]
* - data.link_target [Link target]
* - data.styles [CSS classes separated by spaces]
* - data.filepath [Filepath to image relative to drupal]
* - data.image_url [Full URL to image]
* - data.link_url [Full URL to link]
*/
function ib_process_insert(data) {
// Do whatever I want with the returned JSON data here.
window.close();
}
3. Calling code
Then simply call Image Browser with your module name: <a href="/index.php?q=imagebrowser/my_module">Launch Image Browser</a>