Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty parameters are being converted to empty arrays #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions bem.function.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

/**
* @file
* Add "bem" function for Pattern Lab & Drupal
* Add "bem" function for Pattern Lab & Drupal.
*/

use Drupal\Core\Template\Attribute;
Expand All @@ -27,11 +28,11 @@
}
}

// Ensure array arguments.
if (!is_array($modifiers)) {
// Ensure array arguments only if a value is present.
if (isset($modifiers) && !is_array($modifiers)) {
$modifiers = [$modifiers];
}
if (!is_array($extra)) {
if (isset($extra) && !is_array($extra)) {
$extra = [$extra];
}

Expand All @@ -41,7 +42,7 @@
$classes[] = $blockname . '__' . $base_class;

// Set blockname--modifier classes for each modifier.
if (isset($modifiers) && is_array($modifiers)) {
if (isset($modifiers)) {
foreach ($modifiers as $modifier) {
$classes[] = $blockname . '__' . $base_class . '--' . $modifier;
};
Expand All @@ -52,15 +53,15 @@
// Set base class.
$classes[] = $base_class;
// Set base--modifier class for each modifier.
if (isset($modifiers) && is_array($modifiers)) {
if (isset($modifiers)) {
foreach ($modifiers as $modifier) {
$classes[] = $base_class . '--' . $modifier;
};
}
}

// If extra non-BEM classes are added.
if (isset($extra) && is_array($extra)) {
if (isset($extra)) {
foreach ($extra as $extra_class) {
$classes[] = $extra_class;
};
Expand All @@ -70,7 +71,7 @@
$attributes = new Attribute();

// Iterate the attributes available in context.
foreach($context['attributes'] as $key => $value) {
foreach ($context['attributes'] as $key => $value) {
// If there are classes, add them to the classes array.
if ($key === 'class') {
foreach ($value as $class) {
Expand Down Expand Up @@ -99,4 +100,4 @@
return $attributes;
}

}, array('needs_context' => true, 'is_safe' => array('html')));
}, array('needs_context' => TRUE, 'is_safe' => array('html')));