Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

323: Menu links to use link function #324

Merged
merged 2 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions components/_patterns/02-molecules/menus/_menu-item.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"li_blockname": item_blockname,
} %}
{% block list_item_content %}
{% include "@atoms/01-links/link/link.twig" with {
"link_content": item.title,
"link_url": item.url,
"link_base_class": item_base_class|default(menu_class ~ '__link'),
"link_modifiers": item_modifiers,
{# Any icons, etc. can go inside this set link_title statement. #}
{% set link_title %}{{ item.title }}{% endset %}
{# You can add other attributes (id, etc.) inside this link_attributes array. #}
{% set link_attributes = {
class: bem(item_base_class|default(menu_class ~ '__link'), (item_modifiers)),
} %}
{{ link(link_title, item.url, add_attributes(link_attributes)) }}
{% if item.below %}
<span class="expand-sub"></span>
{{ menus.menu_links(item.below, attributes, menu_level + 1, menu_class, menu_modifiers, menu_blockname, item_base_class, original_item_modifiers, item_blockname) }}
Expand Down
26 changes: 22 additions & 4 deletions components/_twig-components/functions/pl_link.function.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<?php
/**
* @file
* Add "link" function for Pattern Lab.
* Simple "link" function for Pattern Lab to replicate Drupal functionality.
*/

$function = new Twig_SimpleFunction('link', function ($string) {
return $string;
});
$function = new Twig_SimpleFunction('link', function ($title, $url, $attributes = array()) {
// Make it into an array if it is not already.
if (!is_array($attributes)) {
$attributes = [$attributes];
}

$attributes_string = '';

// Create attributes.
if (isset($attributes) && is_array($attributes)) {
foreach ($attributes as $key => $value) {
// handle BEM function differently than rest.
if ($key == 'class') {
$attributes_string .= $value . ' ';
} else {
$attributes_string .= $key . '="' . $value . '" ';
}
};
}
return '<a href="' . $url . '"' . $attributes_string . '>' . $title . '</a>';
}, array('is_safe' => array('html')));