欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

更改日期和时间的标签 Change Label of date and time 有大用

我试图找出一种方法来改变它们在节点上显示的日期和时间的标签。它们只显示为“从日期”和“到日期”,并且没有字段随时间框,我的用户不会知道在该框中输入时间。Google搜索只找到了一个问题,这实际上是我遇到的同样的问题,但没有人回应。这个问题在这里:

http://drupal.org/node/281112#comment-1108281

我不介意编辑.module文件,但我已经通过模块附带的那些,我似乎找不到标签在任何地方。有人能指点我的方向吗?

谢谢。

注释

arlinsandbulte的图片

 

版:5.x-2.3»7.x-1.x-dev
类别:支持»功能

不,我不认为有任何好的方法这样做。
我会把它变成一个功能请求,并移动到HEAD。

arlinsandbulte的图片

 

有没有办法这样做6.x通过钩形式alter或什么?
现在标签显示为[ - 年] [ - 月] [ - 天],我想把它更改为[年] [月] [日] 
有一个例子,如何做到某个地方?

谢谢!

arlinsandbulte的图片

 

这是疯狂的老,但这是我如何做这样的事情。自己亲自做的有大用见   node-admin/8747

function mymodule_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'event_node_form':  //content type of form
      $form['field_event_start_date']['#pre_render'] = array('mymodule_date_label');  //field name of the date
      break;
  }
}
/**
 *  Updates date labels on node form.
 */
function mymodule_date_label($element) {
  $element[0]['value']['#title'] = t('Start Date');
  $element[0]['value2']['#title'] = t('End Date');
  return $element;
}

http://api.drupal.org/api/drupal/developer-topics--forms_api_reference ....

查看api引用并注意pre_render需要是一个数组。我做错了,如果我的模块被调用最后一些其他模块在这里添加的东西,我会重置该数组。只要在做你的时候记住这一点。

arlinsandbulte的图片

 

谢谢,iLLin。有一个地狱的时间弄明白如何改变这些值与形式alter。

andypost的图片

 

如果日期字段允许更改From-To的标签,我们应该决定翻译。
一旦输入标签,这是一个用户文本,不翻译与区域设置模块

arlinsandbulte的图片

 

谢谢iLLin。我想改变它无处不在,所以我补充说

$form['date_filter']['min']['#title'] = t('From');

到我的form_alter。

arlinsandbulte的图片

 

状态:活性»修正

我为日期和时间标签添加了主题函数,类似于选择小部件中的年,月,日等标签的主题函数。现在,您可以覆盖theme_date_part_label_date()和theme_date_part_label_time()。

 

状态:固定»关闭(固定)

自动关闭 - 问题固定为2周没有活动。

来自  https://www.drupal.org/node/334435



 

Hello,

I'm trying to figure out a way to change the label of the date and time how they appear on the node. They only appear as "From Date" and "To Date," and there is no field over time box, and my users won't know to enter the time in that box. Google search only picked up one issue, which actually is the same issue I'm having, but nobody responded to it. That issue is here:

http://drupal.org/node/281112#comment-1108281

I don't mind editing the .module file, but I have looked through the ones that came with the module and I can't seem to find that label anywhere. Can someone point me in the right direction?

Thanks.

Comments

arlinsandbulte的图片

 

Version:5.x-2.3» 7.x-1.x-dev
Category:support» feature

No, I don't think there is any nice way of doing this.
I'll turn this into a feature request and move it to HEAD.

arlinsandbulte的图片

 

Is there a way of doing this for 6.x by hook form alter or something?
Right now the label is showing as [ -Year ] [ -Month ] [ -Day ] and I would like to change it to [ Year ] [ Month ] [ Day ]
Is there an example of how to do this somewhere?

Thanks!

arlinsandbulte的图片

 

This is crazy old, but this is how I do things like this.

function mymodule_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'event_node_form':  //content type of form
      $form['field_event_start_date']['#pre_render'] = array('mymodule_date_label');  //field name of the date
      break;
  }
}
/**
 *  Updates date labels on node form.
 */
function mymodule_date_label($element) {
  $element[0]['value']['#title'] = t('Start Date');
  $element[0]['value2']['#title'] = t('End Date');
  return $element;
}

http://api.drupal.org/api/drupal/developer--topics--forms_api_reference....

Review the api reference and notice the pre_render needs to be an array. I am doing this wrong as if my module was called last and some other module was adding something here, I would reset that array. Just keep that in mind when doing yours.

arlinsandbulte的图片

 

Thanks, iLLin. Was having a hell of a time figuring out how to change these values with form alter.

andypost的图片

 

If date field will allow to change a labels for From-To so we should decide on translation.
Once label is entered so It's a user text which does not translates with locale module

arlinsandbulte的图片

 

Thanks iLLin. i wanted to change it everywhere, so i added

$form['date_filter']['min']['#title'] = t('From');

to my form_alter.

arlinsandbulte的图片

 

Status:Active» Fixed

I added theme functions for the date and time labels, similar to the theme functions for the year, month, day, etc labels in the select widget. Now you can override theme_date_part_label_date() and theme_date_part_label_time().

 

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

来自  https://www.drupal.org/node/334435

 


普通分类: