发布于 2019-04-02 09:05:57
出版日期模块提供了一个函数来定义可以使用哪些格式化程序。我添加了一个补丁,我们在本地维护它,以便将定义的"timestamp_ap_style“格式添加到选项中。或者,我可以将其添加到自定义模块中,但该修补程序似乎更有意义。
function publication_date_field_formatter_info_alter(array &$info) {
$info['timestamp']['field_types'][] = 'published_at';
$info['timestamp_ago']['field_types'][] = 'published_at';
$info['timestamp_ap_style']['field_types'][] = 'published_at';
}
更新:最近,我在智能日期中遇到了一个C3
,它的需求与AP样式日期模块中的需求相同。所以,我试过了,效果很好。
/**
* Plugin implementation of the 'timestamp' formatter as time ago.
*
* @FieldFormatter(
* id = "timestamp_ap_style",
* label = @Translation("AP Style"),
* field_types = {
* "datetime",
* "timestamp",
* "created",
* "changed",
* "published_at",
* }
* )
*/
简单而优雅。
https://drupal.stackexchange.com/questions/278283
复制