You are here

function epsacrop_form_file_entity_edit_alter in EPSA Crop - Image Cropping 7.2

Implements hook_form_file_entity_edit_alter(). Add epsacrop to file_entity edit form.

1 call to epsacrop_form_file_entity_edit_alter()
epsacrop_form_media_edit_alter in ./epsacrop.module
Implements hook_form_media_edit_alter(). Add epsacrop to media edit form.

File

./epsacrop.module, line 585
The main file of module

Code

function epsacrop_form_file_entity_edit_alter(&$form, $form_state) {
  if (!_epsacrop_access() || !isset($form['preview']['#file']) || $form['preview']['#file']->type != 'image') {
    return;
  }
  _epsacrop_include_header_html();
  $setting = array(
    'entity_type' => 'all',
    'field_name' => 'all',
    'bundle' => 'all',
  );
  $file = $form['preview']['#file'];
  $info = image_get_info($file->uri);
  $setting['fid'] = $file->fid;
  $setting['url'] = str_replace('%27', '\\%27', image_style_url('epsacrop_thumb', $file->uri));
  $setting['size'] = array(
    $info['width'],
    $info['height'],
  );

  // Fix a strange bug when the image's name contains strange chars, like +
  $preview_file = image_style_path('epsacrop_thumb', $file->uri);
  if (!file_exists($preview_file)) {
    image_style_create_derivative(image_style_load('epsacrop_thumb'), $file->uri, $preview_file);
  }
  $markup = "<a href=\"javascript:Drupal.EPSACrop.dialog('" . $setting['entity_type'] . "', '" . $setting['field_name'] . "', '" . $setting['bundle'] . "', '" . $setting['fid'] . "', '" . $setting['url'] . "', [" . $setting['size'][0] . "," . $setting['size'][1] . "]);\" class=\"button epsacrop\">" . t("manage image crops") . "</a>";
  $form['epsacrop'] = array(
    '#type' => 'markup',
    '#markup' => $markup,
  );
}