Shomeya Utility module for Drupal
This module provides several useful features, such as an environment indicator, a style guide, some render elements and template functions/helpers., (*1)
This module provide a helper class to access information about the build, such as latest Git commit, date, time, as well as who and where the build was packaged. This information is available in the status report at admin/reports/status. It also includes links to Github for relevant commits as long as the Github URL is set in settings.php:, (*2)
$config['shomeya_utility.settings']['github_url'] = 'https://github.com/shomeya/projectname';
Environment indicator
An environment indicator is available that provides text and an icon indicating which environment you are viewing:, (*3)
, (*4)
This functionality is based on the enviroment specified in the settings.json file and is mapped in src/Environment.php., (*5)
Style Guide
This module provides a sample style guide at styleguide/web with additional pages for form elements and Drupal elements at styleguide/web/drupal/form and styleguide/web/drupal/elements., (*6)
Elements
A time element is defined in src/Element/Time.php. This element also supports optionally rendering as a dynamic 'time ago' with Javascript if the option is enabled., (*7)
$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',
],
];
Template functions/helpers
There are several helper function that are exposed to Twig templates:, (*8)
URL from URI
This helper turns a Drupal URI (such as internal:/about-us
, entity:node/1234
, or base:robots.txt
) into a fully qualified URL:, (*9)
<a href="{{ url_from_uri(node.field_link.uri) }}">My Link</a>
It supports options that will be based to Url::fromUri() such as query
, absolute
, https
, and more:, (*10)
<a href="{{ url_from_uri(node.field_link.uri, {absolute: true}) }}">My Link</a>
Time
Supports creation of a time element from a timestamp:, (*11)
{# Without value provided a value will be formatted from the timestamp #}
{{ time(item.timestamp) }}
It supports an optional value to be displayed if you wish to customize the date display:, (*12)
{{ time(item.timestamp, item.date) }}
Finally it supports all options that can be passed to the time element, and additional options for generating a value if one is not provided:, (*13)
{# Type and format correspond to options passed to DateFormatter::format() #}
{{ time(item.timestamp, null, {type: custom, format: 'F j Y'}) }}
The last example will output something like:, (*14)
<time datetime="2016-02-26T14:59:20-08:00">February 26 2016</time>
Time ago
Support time element from timestamp with timeago set to true:, (*15)
{{ time_ago(item.timestamp) }}
The output will be:, (*16)
<time datetime="2016-02-26T14:59:20-08:00" data-drupal-time-ago>Fri, 02/26/2016 - 14:59</time>
This also automatically includes jquery.timeago.js which will format the value as a time ago, such as 'less than a minute ago.', (*17)
This support the same options for value and options as the time helper., (*18)
Time From String
This function supports generating a time element from a date string parsed with strtotime():, (*19)
{{ time_from_string('Fri, 02/26/2016 - 14:59') }}
Also allows for value, options., (*20)
Time ago from string
Supports generating a time ago tag from a string:, (*21)
{{ time_ago_from_string('Fri, 02/26/2016 - 14:59') }}