제거 버튼을 위해 HTML을 해킹하면 작동하지 않습니다. 이미지를 제거하지 않고 페이지를 새로 고칩니다. 대신에있는 핵심 이미지 필드의 theme_image_widget
콜백에서 복사 했습니다 docroot/modules/image/image.field.inc
.
/**
* Implements theme_mymodule_thumb_upload theme callback.
*/
function theme_mymodule_thumb_upload($variables) {
$element = $variables['element'];
$output = '';
$output .= '<div class="image-widget form-managed-file clearfix">';
// My uploaded element didn't have a preview array item, so this didn't work
//if (isset($element['preview'])) {
// $output .= '<div class="image-preview">';
// $output .= drupal_render($element['preview']);
// $output .= '</div>';
//}
// If image is uploaded show its thumbnail to the output HTML
if ($element['fid']['#value'] != 0) {
$output .= '<div class="image-preview">';
// Even though I was uploading to public:// the $element uri was pointing to temporary://system, so the path to the preview image was a 404
//$output .= theme('image_style', array('style_name' => 'thumbnail', 'path' => file_load($element['fid']['#value'])->uri, 'getsize' => FALSE));
$output .= theme('image_style', array('style_name' => 'thumbnail', 'path' => 'public://'.$element['#file']->filename, 'getsize' => FALSE));
$output .= '</div>';
}
$output .= '<div class="image-widget-data">';
if ($element['fid']['#value'] != 0) {
$element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
}
// The remove button is already taken care of by rendering the rest of the form. No need to hack up some HTML!
$output .= drupal_render_children($element);
$output .= '</div>';
$output .= '</div>';
return $output;
}
이 테마 기능을 사용하여 요소를 렌더링하십시오.
/**
* Implements hook_theme().
*/
function mymodule_theme() {
return array(
'mymodule_thumb_upload' => array(
'render element' => 'element',
)
);
}
양식 요소 정의 :
$form['upload_image'] = array(
'#type' => 'managed_file',
'#default_value' => $value,
'#title' => t('Image'),
'#description' => t('Upload an image'),
'#upload_location' => 'public://',
'#theme' => 'mymodule_thumb_upload',
'#upload_validators' => array(
'file_validate_is_image' => array(),
'file_validate_extensions' => array('jpg jpeg gif png'),
'file_validate_image_resolution' => array('600x400','300x200'),
),
);
if (!empty($form['#file'])) {
`print drupal_render_children ($ form);`까지.tpl.php
파일에 쓰 나요? 그렇지 않으면이 부분을 어디에 써야합니까?