function epsacrop_element_process in EPSA Crop - Image Cropping 7.2
Helper function that add a link in image widget field to open a dialog for the crops.
@access private
Return value
void
1 string reference to 'epsacrop_element_process'
- epsacrop_element_info_alter in ./
epsacrop.module - Implements hook_element_info_alter.
File
- ./
epsacrop.module, line 640 - The main file of module
Code
function epsacrop_element_process($element, $form_state, $form) {
if (!isset($element['#field_name']) || !_epsacrop_access()) {
return $element;
}
_epsacrop_include_header_html();
$styles = _epsacrop_load_styles_by_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
if (count($styles) == 0) {
return $element;
}
$setting = array(
'entity_type' => $element['#entity_type'],
'field_name' => $element['#field_name'],
'bundle' => $element['#bundle'],
);
if (isset($element['#file']) && is_object($element['#file']) && ($file = $element['#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);
}
}
if ($element['#type'] == 'media') {
//for media, need to include the media elements even if the file is not defined, because it's not defined when file initially selected
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => array(
'epsacrop_dialog' => array(
$element['#id'] . '--widget' => $setting,
),
),
);
$element['#attached']['js'][] = drupal_get_path('module', 'epsacrop') . '/js/epsacrop-media.js';
$element['epsacrop'] = array(
'#type' => 'link',
'#href' => '',
'#title' => t('Manage image crops'),
'#attributes' => array(
'class' => array(
'button',
'manage-crop',
),
),
'#options' => array(
'fragment' => FALSE,
'external' => TRUE,
),
'#weight' => 0,
);
}
elseif (isset($setting['fid'])) {
$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] . "]);\">" . t("manage image crops") . "</a>";
$element['epsacrop'] = array(
'#type' => 'markup',
'#markup' => $markup,
);
}
return $element;
}