function imagecrop_linkitem in Image javascript crop 7
Same name and namespace in other branches
- 5 imagecrop.module \imagecrop_linkitem()
- 6 imagecrop.module \imagecrop_linkitem()
Helper function to add the imagecrop button.
Parameters
$element Element being changed:
$variables Array with all vars for the button:
- fid: from the file to crop
- styles: The enabled styles
- text: Text to display in link
- display: Css display property value
- js_file: JS file to use => imagecrop_field.js, or imagecrop_field_media_v1.js
Return value
link for opening the imagecrop admin.
3 calls to imagecrop_linkitem()
- imagecrop_form_file_entity_edit_alter in ./
imagecrop.module - Implements hook_form_file_entity_edit_alter(). Add imagecrop to file_entity edit form.
- imagecrop_form_user_profile_form_alter in ./
imagecrop.module - Implements hook_form_user_profile_form_alter(). Add imagecrop to profile picture, if enabled.
- imagecrop_process_form_element in ./
imagecrop.module - Process function for imagecrop-enabled fields.
File
- ./
imagecrop.module, line 518 - Provides a javascript toolbox through an imagecache action.
Code
function imagecrop_linkitem(&$element, $variables) {
$popup_link_function = variable_get('imagecrop_popup', 'imagecrop_jquery_dialog');
$width = variable_get('imagecrop_popup_width', 700);
$height = variable_get('imagecrop_popup_height', 600);
$styles = $variables['styles'];
// Construct all required urls
$skip_preview = variable_get('imagecrop_skip_preview', FALSE);
$first_style = current($styles);
$action = $skip_preview ? 'crop' : 'overview';
$url = 'imagecrop/' . $action . '/' . $variables['fid'] . '/' . $first_style . '/';
$media_url = 'imagecrop/' . $action . '/fid/' . $first_style . '/';
$settings_url = url('imagecrop/' . $action . '/fid/' . $first_style, array(
'absolute' => TRUE,
));
$setting = array(
'imagecrop' => array(
'cropUrl' => $settings_url,
'popupWidth' => $width,
'popupHeight' => $height,
),
);
// Attach js
$element['#attached']['js'][] = array(
'type' => 'setting',
'data' => $setting,
);
$element['#attached']['js'][] = drupal_get_path('module', 'imagecrop') . '/js/' . $variables['js_file'];
// Attach dialog if required
if ($popup_link_function == 'dialog') {
$element['#attached']['library'][] = 'ui.dialog';
}
if (isset($element['#entity_type'], $element['#bundle'], $element['#field_name'])) {
$url .= $element['#entity_type'] . '/' . $element['#bundle'] . '/' . $element['#field_name'];
$media_url .= $element['#entity_type'] . '/' . $element['#bundle'] . '/' . $element['#field_name'];
}
elseif ($skip_preview) {
$url .= 'none/none';
$media_url .= 'none/none';
}
$element['imagecrop-url'] = array(
'#type' => 'hidden',
'#value' => url($media_url, array(
'absolute' => TRUE,
)),
'#attributes' => array(
'class' => 'imagecrop-url',
),
);
$url = url($url, array(
'absolute' => TRUE,
));
$style = isset($variables['display']) ? ' style="display:' . $variables['display'] . ';"' : '';
if ($popup_link_function != 'basic' && function_exists($popup_link_function) && ($link = $popup_link_function($url, $width, $height, $variables['text'], $style, $element))) {
return $link;
}
else {
return '<a href="' . $url . '"' . $style . ' onclick="Drupal.Imagecrop.openPopup(this); return false;" class="button imagecrop-button">' . $variables['text'] . '</a>';
}
}