我正在尝试更改节点添加表单上的图像小部件中的“alt”和“标题”标签。
我已经尝试过这两个钩子:
hook_field_widget_form_alter
hook_form_alter
我无法找到需要去哪里才能成功更改标签。有人可以指导我找到适当的方法来连接并更改它们吗?如果有影响的话,我会从自定义模块中点击这些。通过主题来吸引他们对我来说也很好。
有人有什么想法吗?
你必须添加一个额外的处理功能对于小部件表单。
您还可以使用dpm($元素) with Devel http://drupal.org/project/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 https://drupal.stackexchange.com/questions/32861/how-do-i-alter-image-field-code-without-hacking-core
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)