您必须为widget窗体添加额外的Proccess功能。
您还可以使用DPM($元素)与Devel模块可以找到更多的细节有关可用键,选项等
// Alter image Title for field_top_image instance
function MYMODULE_field_widget_form_alter(&$element, &$form_state, $context) {
// If this is an image field type of instance 'field_image_top'
if ($context['field']['field_name'] == 'field_image_top') {
// Loop through the element children (there will always be at least one).
foreach (element_children($element) as $key => $child) {
// Add the new process function to the element
//dpm($element);
$element[$key]['#process'][] = 'MYMODULE_image_field_widget_process';
}
}
}
function MYMODULE_image_field_widget_process($element, &$form_state, $form) {
// Change the title field label and description
//dpm($element);
$element['title']['#title'] = 'NEW TITLE';
$element['title']['#description'] = 'SOME NEW DESCRIPTION HERE.';
// Return the altered element
return $element;
}
看到一个类似的问题:https://drupal.stackexchange.com/questions/32861/how-do-i-alter-image-field-code-without-hacking-core
合作。谢谢! – Jnicola
谢谢!好的样板解决方案。 – oknate
不错,如果你希望标题在ALT之上,如果你使用标题作为标题和ALT作为图像的描述/标题,你也可以改变权重 - 你可能想要这样做。例如:$ element ['title'] ['#weight'] = 1;和$ element ['alt'] ['#weight'] = 2; – klidifia