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

Commit

Permalink
attempt to get function to use attributes in Drupal
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Willhite committed Jul 11, 2017
1 parent 541c97d commit eb683e7
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ pattern-lab
# NPM
node_modules
npm-debug.log

.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
* - heading_link_blockname - override the link block name
*/
#}
{% set heading_base_class_var = heading_base_class|default('heading-1') %}

<h1 class="{{ heading_base_class_var }}{% for modifier in heading_modifiers %} {{ heading_base_class_var }}--{{ modifier }}{% endfor %}{% if heading_blockname %} {{ heading_blockname }}__{{ heading_base_class_var }}{% endif %}">
<h1{{ bem('heading-1', (heading_1_modifiers), heading_1_blockname)|raw }}>
{% if heading_url %}
{% include "@atoms/01-links/link/link.twig"
with {
Expand Down
2 changes: 1 addition & 1 deletion components/_patterns/02-molecules/_block.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @see template_preprocess_block()
*/
#}
<div{{ attributes }}>
<div{{ bem('block') }}>
{{ title_prefix }}
{% if label %}
<h2{{ title_attributes.addClass('heading-2') }}>{{ label }}</h2>
Expand Down
1 change: 0 additions & 1 deletion components/_twig-components/filters/.gitkeep

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Bring Drupal filters in just so Pattern Lab doesn't bork.
*/

$filter = new Twig_SimpleFilter('clean_class', function ($string) {
return $string;
});
if (!class_exists('Drupal')) {
$filter = new Twig_SimpleFilter('clean_class', function ($string) {
return $string;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Bring Drupal filters in just so Pattern Lab doesn't bork.
*/

$filter = new Twig_SimpleFilter('safe_join', function ($string) {
return $string;
});
if (!class_exists('Drupal')) {
$filter = new Twig_SimpleFilter('safe_join', function ($string) {
return $string;
});
}
19 changes: 19 additions & 0 deletions components/_twig-components/filters/d_t.filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* @file
* Add "t" filter for Pattern Lab.
*
* Bring Drupal filters in just so Pattern Lab doesn't bork.
*/

if (!class_exists('Drupal')) {
$filter = new Twig_SimpleFilter('t', function ($string, $array = array()) {
if (is_string($string) && is_array($array)) {
$haystack = $string;
foreach ($array as $needle => $replace) {
$haystack = str_replace($needle, $replace, $haystack);
}
return $haystack;
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Bring Drupal filters in just so Pattern Lab doesn't bork.
*/

$filter = new Twig_SimpleFilter('without', function ($string) {
return $string;
});
if (!class_exists('Drupal')) {
$filter = new Twig_SimpleFilter('without', function ($string) {
return $string;
});
}
17 changes: 0 additions & 17 deletions components/_twig-components/filters/t.filter.php

This file was deleted.

44 changes: 44 additions & 0 deletions components/_twig-components/functions/bem.function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @file
* Add "bem" function for Pattern Lab & Drupal
*/

$function = new Twig_SimpleFunction('bem', function ($base_class, $modifiers = array(), $blockname = '') {
$classes = array();
// If using a blockname to override default class.
if ($blockname) {
// Set blockname class.
$classes[] = $blockname . '__' . $base_class;
// Set blockname--modifier classes for each modifier.
if (isset($modifiers) && is_array($modifiers)) {
foreach ($modifiers as $modifier) {
$classes[] = $blockname . '__' . $base_class . '--' . $modifier;
};
}
}
// If not overriding base class.
else {
// Set base class.
$classes[] = $base_class;
// Set base--modifier class for each modifier
if (isset($modifiers) && is_array($modifiers)) {
foreach ($modifiers as $modifier) {
$classes[] = $base_class . '--' . $modifier;
};
}
}

if (class_exists('Drupal')) {
$classLoader = new ClassLoader();
$classLoader.loadClass("Attribute");
$attributes = new Attribute();
$attributes['class'][] = $classes;
}
else {
$classString = implode(' ', $classes);
$classesSafe = ' class="' . $classString . '"';
return $classesSafe;
}

});
19 changes: 0 additions & 19 deletions components/_twig-components/functions/blockname.function.php

This file was deleted.

11 changes: 11 additions & 0 deletions components/_twig-components/functions/d_kint.function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* @file
* Add "kint" function for Pattern Lab.
*/

if (!class_exists('Drupal')) {
$function = new Twig_SimpleFunction('kint', function ($string) {
return $string;
});
}
11 changes: 11 additions & 0 deletions components/_twig-components/functions/d_link.function.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/**
* @file
* Add "link" function for Pattern Lab.
*/

if (!class_exists('Drupal')) {
$function = new Twig_SimpleFunction('link', function ($string) {
return $string;
});
}
9 changes: 0 additions & 9 deletions components/_twig-components/functions/kint.function.php

This file was deleted.

9 changes: 0 additions & 9 deletions components/_twig-components/functions/link.function.php

This file was deleted.

1 change: 0 additions & 1 deletion components/_twig-components/tags/.gitkeep

This file was deleted.

1 change: 0 additions & 1 deletion components/_twig-components/tests/.gitkeep

This file was deleted.

3 changes: 3 additions & 0 deletions templates/content/page-title.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
{% include "@atoms/02-text/00-headings/heading-1/heading-1.twig"
with {
"heading": title,
"heading_1_modifiers": {
1: "drupal-test"
}
}
%}
{% endif %}
Expand Down

0 comments on commit eb683e7

Please sign in to comment.