drupal-twig-extensions
Version:
JavaScript implementation of Drupal’s Twig extensions
49 lines (46 loc) • 1.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.acceptedArguments = void 0;
exports.link = link;
exports.options = exports.name = void 0;
var _definition = require("../create_attribute/definition.cjs");
/**
* @file The link function
*
* Docs for TwigExtension::getLink (Drupal 9.3.x):
*
* ```
* new TwigFunction('link', [$this, 'getLink'])
* ```
*/
const name = 'link';
exports.name = name;
const options = {};
exports.options = options;
const acceptedArguments = [{
name: 'text'
}, {
name: 'url'
}, {
name: 'attributes',
defaultValue: {}
}];
/**
* Gets a rendered link from a url object.
*
* @param {string} text
* The link text for the anchor tag as a translated string.
* @param {string|\Drupal\Core\Url} url
* The URL object or string used for the link.
* @param {Object|\Drupal\Core\Template\Attribute} attributes
* An optional Object or Attribute object of link attributes.
*
* @returns {string}
* A link to the given URL.
*/
exports.acceptedArguments = acceptedArguments;
function link(text, url, attributes = {}) {
return `<a href="${url}"${(0, _definition.createAttribute)(attributes)}>${text}</a>`;
}