Currently, you can only insert image files with BUEditor module like shown on the picture:

enter image description here

On a Drupal 7 website with file field enabled to upload images I am looking for ways to integrate both.

The module's developer said on https://www.drupal.org/project/bueditor/issues/1035760

This could be implemented by a custom button.

There is a code on https://www.drupal.org/project/bueditor/issues/770144 which allegedly works for Drupal 6:

global $base_url;
$file_path = $base_url . url(file_directory_path());
// preset for preview
$preview_preset = "bueditor-previews";
// preset for inline inserted photo
$inline_preset = "inline-inserted-photo";
// preset for linked original photo
$original_preset = "original-photo";

drupal_add_js(array('myBueImage' => array(
  'file_path' => "$file_path/",
  'preview_path' => "$file_path/imagecache/$preview_preset/",
  'inline_path' => "$file_path/imagecache/$inline_preset/",
  'original_path' => "$file_path/imagecache/$original_preset/"
)), 'setting');

return 'js:
  var $output = \'<div style="width:280px;text-align:center">\';
  $("table#upload-attachments small:contains("+ Drupal.settings.myBueImage.file_path +")").each(function(){
    var $filename = $(this).text().split("/").reverse()[0];
    var $preview = \'<img src="\'+ Drupal.settings.myBueImage.preview_path + $filename +\'" style="margin:0 4px 0 0;padding:2px;border:1px solid #ccc;cursor:pointer" class="bueditor-photo-preview" id="\'+ $filename +\'" />\';
    $output += $preview;
  $output += \'</div>\';
  $output += \'<div style="width:280px;margin-top:4px;padding-top:2px;padding-left:4px;border-top:1px solid #ccc;"><label for="bueditor-photo-align">Align: </label><select name="bueditor-photo-align" class="form-select" id="bueditor-photo-align"><option value="nolalign">&lt;none&gt;</option><option value="sinistra">Left</option><option value="destra">Right</option></select></div>\';
  E.dialog.open("Users", $output);
  $("img.bueditor-photo-preview").click(function() {
    var $filename = $(this).attr("id");
    var $txt = \'<a href="\'+ Drupal.settings.myBueImage.original_path + $filename +\'" target="_blank" rel="thickbox"><img src="\'+ Drupal.settings.myBueImage.inline_path + $filename +\'" class="\'+ $("select#bueditor-photo-align").val() +\'" /></a>\';
    return false;

Could anyone help me to make this work for Drupal 7?

  • Since you asking help to make the code work for Drupal 7, I take you tried using it, but it didn't work. In that case, did you get any error? What error? Did you check there is any change in the way one of the three functions the code is using is called in Drupal 7? – kiamlaluno May 1 '18 at 12:01
  • Also, did you install the modules the issue report you linked is referring to? – kiamlaluno May 1 '18 at 12:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.