Drupal 7:如何更改图像字段小部件“alt"或标题"标签 [英] Drupal 7: How to alter image field widget "alt" or title" label

查看:12
本文介绍了Drupal 7:如何更改图像字段小部件“alt"或标题"标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在节点添加表单上更改图像小部件中的alt"和标题标签.

I am trying to change the "alt" and title" labels in the Image Widget on the node add form.

这两个钩子我都试过了:

hook_field_widget_form_alter
hook_form_alter

我找不到成功更改标签所需的位置.有人可以指导我以适当的方式来解决这个问题并改变它们吗?如果它有所作为,我会从自定义模块中获得这些.通过主题击中它们对我来说也很好.

I was unable to find where I needed to go to successfully alter the label. Could some one please direct me to the appropriate way to hook into this and alter them? I'm hitting these from a custom module if it makes a difference. Hitting them via the theme would be fine for me as well.

有什么想法吗?

推荐答案

您必须为小部件表单添加一个额外的处理功能.

You have to add an extra Proccess function for the widget form.

您还可以将 dpm($element)Devel 模块一起使用查找有关可用键、选项等的更多详细信息.

You can also use dpm($element) with Devel module to find more details about available keys, options etc.

// 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

这篇关于Drupal 7:如何更改图像字段小部件“alt"或标题"标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆