shomeya / shomeya_utility
Shomeya 适用于 Drupal 的实用工具
This package is not auto-updated.
Last update: 2024-09-14 20:09:32 UTC
README
本模块提供了一些有用功能,例如环境指示器、风格指南、一些渲染元素和模板函数/辅助函数。
构建元数据
本模块提供了一个辅助类,用于访问有关构建的信息,例如最新的 Git 提交、日期、时间以及谁以及在哪里打包了构建。这些信息在状态报告中可用,在 admin/reports/status。如果 settings.php 中设置了 Github URL,它还包括指向 Github 上相关提交的链接。
$config['shomeya_utility.settings']['github_url'] = 'https://github.com/shomeya/projectname';
环境指示器
可用环境指示器,提供文本和图标,指示您正在查看哪个环境。
此功能基于 settings.json 文件中指定的环境,并在 src/Environment.php 中映射。
风格指南
本模块在 styleguide/web 提供了一个示例风格指南,并附加了 form 元素和 Drupal 元素在 styleguide/web/drupal/form 和 styleguide/web/drupal/elements 中的额外页面。
元素
时间元素在 src/Element/Time.php 中定义。此元素还支持在启用选项的情况下以动态的 'time ago' 的方式使用 JavaScript 进行渲染。
$build = [ '#type' => 'time', '#timestamp' => '1456527560', // Unix timestamp to use for the date, will be used to populate a ISO 8601 in the 'datetime' attribute of the tag '#value' => 'Friday, Feb. 26th', // The value to be displayed '#options' => [ 'timeago' => TRUE, // Whether or not the element should be rendered as timeago using javascript ], '#attributes' => [ // additional attributes for the element 'class' => 'my-time-element', ], ];
模板函数/辅助函数
有多个辅助函数可用于向 Twig 模板公开。
从 URI 获取 URL
此辅助函数将 Drupal URI(如 internal:/about-us
、entity:node/1234
或 base:robots.txt
)转换为完全限定的 URL。
<a href="{{ url_from_uri(node.field_link.uri) }}">My Link</a>
它支持基于 Url::fromUri() 的选项,如 query
、absolute
、https
等。
<a href="{{ url_from_uri(node.field_link.uri, {absolute: true}) }}">My Link</a>
时间
支持从时间戳创建时间元素。
{# Without value provided a value will be formatted from the timestamp #} {{ time(item.timestamp) }}
它支持一个可选的值,如果您希望自定义日期显示。
{{ time(item.timestamp, item.date) }}
最后,它支持可以传递给时间元素的任何选项,以及在没有提供值时生成值的附加选项。
{# Type and format correspond to options passed to DateFormatter::format() #} {{ time(item.timestamp, null, {type: custom, format: 'F j Y'}) }}
最后一个示例将输出类似以下内容:
<time datetime="2016-02-26T14:59:20-08:00">February 26 2016</time>
时间前
支持设置 timeago 为 true 的时间元素从时间戳
{{ time_ago(item.timestamp) }}
输出将如下所示:
<time datetime="2016-02-26T14:59:20-08:00" data-drupal-time-ago>Fri, 02/26/2016 - 14:59</time>
这还自动包括 jquery.timeago.js,它将值格式化为时间前,例如 '不到一分钟前'。
这支持与时间辅助函数相同的值和选项。
从字符串获取时间
此函数支持从使用 strtotime() 解析的日期字符串生成时间元素。
{{ time_from_string('Fri, 02/26/2016 - 14:59') }}
还允许使用值和选项。
从字符串获取时间前
支持从字符串生成时间前标签。
{{ time_ago_from_string('Fri, 02/26/2016 - 14:59') }}