function panopoly_widgets_field_widget_form in Panopoly Widgets 7
Implements hook_field_widget_form().
File
- ./
panopoly_widgets.spotlight.inc, line 233 - A specification for the custom spotlight entity that is part of Panopoly Widgets
Code
function panopoly_widgets_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
if ($instance['widget']['type'] == 'panopoly_spotlight_form') {
// Make it a multipart form
$form['#attributes']['enctype'] = 'multipart/form-data';
// Define the element
$element['title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['field_title']) ? $items[$delta]['field_title'] : NULL,
);
$element['link'] = array(
'#title' => t('Link'),
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['link']) ? $items[$delta]['link'] : NULL,
'#maxlength' => 255,
'#linkit' => array(
'enable' => TRUE,
'profile' => 'content_fields',
'button_text' => t('Search for existing content'),
),
);
$instance_settings = $instance['settings'];
$field_settings = $field['settings'];
$element['fid'] = array(
'#title' => t('Image'),
'#type' => 'media',
'#media_options' => array(
'global' => array(
'types' => array(
'image' => 'image',
),
'enabledPlugins' => array(
'media_default--media_browser_1' => 'media_default--media_browser_1',
'upload' => 'upload',
),
'schemes' => array(
'private' => 'private',
'public' => 'public',
),
'file_directory' => isset($instance_settings['file_directory']) ? $instance_settings['file_directory'] : '',
'file_extensions' => isset($instance_settings['file_extensions']) ? $instance_settings['file_extensions'] : 'jpg jpeg gif png',
'max_filesize' => isset($instance_settings['max_filesize']) ? $instance_settings['max_filesize'] : 0,
'min_resolution' => isset($instance_settings['min_resolution']) ? $instance_settings['min_resolution'] : 0,
'max_resolution' => isset($instance_settings['max_resolution']) ? $instance_settings['max_resolution'] : 0,
'uri_scheme' => !empty($field_settings['uri_scheme']) ? $field_settings['uri_scheme'] : file_default_scheme(),
'multiselect' => FALSE,
),
),
'#default_value' => isset($items[$delta]['fid']) ? $items[$delta]['fid'] : NULL,
);
// Allow cropping via the manualcrop module.
if (module_exists('manualcrop') && user_access("use manualcrop")) {
$fid = isset($form_state['values'][$field['field_name']][$langcode][$delta]['fid']) ? $form_state['values'][$field['field_name']][$langcode][$delta]['fid'] : $element['fid']['#default_value'];
$file = !empty($fid) ? file_load($fid) : NULL;
// If the remove button was clicked, then unset the file.
$triggering_parents = !empty($form_state['triggering_element']) ? $form_state['triggering_element']['#parents'] : array();
if (count($triggering_parents) >= 5 && $triggering_parents[4] == 'remove_button' && $triggering_parents[2] == $delta) {
$file = NULL;
}
if (!empty($file)) {
$manualcrop = array(
'manualcrop_enable' => TRUE,
'manualcrop_keyboard' => TRUE,
'manualcrop_thumblist' => FALSE,
'manualcrop_inline_crop' => FALSE,
'manualcrop_crop_info' => TRUE,
'manualcrop_instant_preview' => TRUE,
'manualcrop_instant_crop' => FALSE,
'manualcrop_default_crop_area' => TRUE,
'manualcrop_maximize_default_crop_area' => TRUE,
'manualcrop_styles_mode' => 'include',
'manualcrop_styles_list' => array(
'panopoly_image_spotlight' => 'panopoly_image_spotlight',
),
'manualcrop_require_cropping' => array(),
);
manualcrop_croptool_process($form, $form_state, $element['fid'], $file, $manualcrop);
}
else {
// Mark this element as supporting manualcrop, even if the crop tool
// isn't currently available.
$element['fid']['manualcrop'] = array();
}
}
$element['alt'] = array(
'#title' => t('Alt text'),
'#type' => 'textfield',
'#default_value' => isset($items[$delta]['field_alt']) ? $items[$delta]['field_alt'] : NULL,
);
$element['description'] = array(
'#title' => t('Description'),
'#type' => 'textarea',
'#rows' => '2',
'#resizable' => FALSE,
'#default_value' => isset($items[$delta]['description']) ? $items[$delta]['description'] : NULL,
);
}
return $element;
}