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

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

问题描述





我尝试过这两个钩子:

  hook_field_widget_form_alter 
hook_form_alter

我无法找到我需要去成功更改标签的地方,有人可以指引我适当的方式来勾引并改变它们吗?任何想法的人都可以通过主题对他们进行打击,对我来说也是一样。



b $ b

解决方案

您必须为窗口小部件表单添加额外的Proccess功能



您还可以使用 dpm($ element) Devel 模块e查找有关可用键,选项等的更多详细信息。

  //更改field_top_image实例的标题
函数MYMODULE_field_widget_form_alter (& $ element,& $ form_state,$ context){
//如果这是一个图像字段类型的实例'field_image_top'
if($ context ['field'] ['field_name' ] =='field_image_top'){
//循环遍历元素children(总是至少有一个)。
foreach(element_children($ element)as $ key => $ child){
//向元素
// dpm($ element)添加新的进程函数;
$ element [$ key] ['#process'] [] ='MYMODULE_image_field_widget_process';
}
}
}

函数MYMODULE_image_field_widget_process($ element,& $ form_state,$ form){
//更改标题字段标签和description
// dpm($ element);
$ element ['title'] ['#title'] ='NEW TITLE';
$ element ['title'] ['#description'] ='这里有一些新的描述'。

//返回更改的元素
return $ element;
}

看到类似的问题:https://drupal.stackexchange.com/questions/32861/how-do-i-alter -image-field-code-without-hacking-core


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

I have tried both of these hooks:

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.

Any ideas anyone?

解决方案

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

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;
}

See a similar issue: https://drupal.stackexchange.com/questions/32861/how-do-i-alter-image-field-code-without-hacking-core

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

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