Closed (fixed)
Project:
Image javascript crop
Version:
7.x-1.0-rc3
Component:
PHP
Priority:
Critical
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
22 Feb 2013 at 22:16 UTC
Updated:
22 Feb 2013 at 22:29 UTC
I had an image field on the node.
Certain groups of editor can edit that node.
But my permissions only allows cropping of own images.
What this was doing was removing the field from my node form because the process_imagecrop_form_element method was returning void
/**
* Process function for imagecrop-enabled fields.
*/
function process_imagecrop_form_element($element) {
// Leave alone if we are on the field ui settings.
if (!isset($element['#field_name']) || $element['#id'] == 'edit-picture-upload') {
return $element;
}
$imagecrop = new ImageCrop();
$file = NULL;
$fid = 0;
$new_element = isset($element['#file']);
if ($new_element) {
$imagecrop->setFile($element['#file']);
}
// Media widget
else {
$new_element = FALSE;
if (!empty($element['fid']['#value'])) {
$file = file_load($element['fid']['#value']);
// Only add when the file is an image
if ($file->type != 'image') {
return $element;
}
$imagecrop->loadFile($element['fid']['#value'], TRUE);
}
}
// Leave alone if no access.
global $user;
if (!$imagecrop->hasUserAccess($user)) {
return;
}
$enabled_styles = imagecrop_get_fields_enabled_styles($element['#entity_type'], $element['#field_name'], $element['#bundle']);
// Leave element when no image styles are found for current field.
if (count($enabled_styles) == 0) {
return $element;
}
if ($new_element) {
$element['imagecrop'] = array(
'#type' => 'markup',
'#weight' => 10,
'#suffix' => '</div>',
);
if ($element['fid']['#value']) {
$element['imagecrop']['#prefix'] = '<div class="imagecrop form-item">';
$element['imagecrop']['#markup'] = imagecrop_linkitem($element['fid']['#value'], $element, $enabled_styles);
}
else {
$element['imagecrop']['#prefix'] = '<div class="description">';
$element['imagecrop']['#markup'] = t('After uploading an image you\'ll be able to crop it.');
}
}
// Media module
else {
$fid = (empty($element['fid']['#value']) ? 0 : $element['fid']['#value']);
$prefix = '<div class="imagecrop form-item" style="display: '. ($fid ? 'inline-block' : 'none' ).'">';
$markup = imagecrop_linkitem($element['fid']['#value'], $element, $enabled_styles);
$element['preview']['#suffix'] .= $prefix . $markup . '</div>';
}
return $element;
}
Comments
Comment #1
gitesh.koli commentedI see the issue is fixed in the latest 7.x-1.x branch.
Comment #1.0
gitesh.koli commentedcorrected code.