Skip to content

Commit

Permalink
fix(menu-builder): Allow custom classes in the menu builder (Fixes #41)…
Browse files Browse the repository at this point in the history
… (#42)
  • Loading branch information
Log1x authored Apr 30, 2021
2 parents 51f6710 + 71731de commit ab0d346
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MenuBuilder
protected $menu = [];

/**
* Attributes Map
* The attributes map.
*
* @var array
*/
Expand All @@ -35,15 +35,19 @@ class MenuBuilder
];

/**
* Blacklisted Classes
* The disallowed classes.
*
* @var array
*/
protected $classes = [
protected $disallowedClasses = [
'current-menu',
'current_page',
'sub-menu',
'menu-item',
'menu-item-type-post_type',
'menu-item-object-page',
'menu-item-type-custom',
'menu-item-object-custom',
'menu_item',
'page-item',
'page_item',
Expand Down Expand Up @@ -88,10 +92,7 @@ protected function filter($menu = [])

return array_map(function ($item) {
$classes = array_filter($item->classes, function ($class) {
return array_key_exists(
$class,
array_flip($this->classes)
);
return ! in_array($class, $this->disallowedClasses);
});

$item->classes = is_array($classes) ? implode(' ', $classes) : $classes;
Expand Down

0 comments on commit ab0d346

Please sign in to comment.