Created
September 20, 2017 00:27
-
-
Save Log1x/358dd055554363488f6220c89a4ec358 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Walker; | |
use Roots\Soil\Nav\NavWalker as Soil; | |
/** | |
* Return if Soil does not exist. | |
*/ | |
if (!class_exists('Roots\Soil\Nav\NavWalker')) { | |
return; | |
} | |
/** | |
* Navigation | |
*/ | |
class Navigation extends Soil | |
{ | |
public function __construct() | |
{ | |
parent::__construct(); | |
remove_filter('nav_menu_css_class', [$this, 'cssClasses'], 10); | |
add_filter('nav_menu_css_class', [$this, 'itemClasses'], 10, 4); | |
} | |
/** | |
* @param string $output | |
* @param int $depth | |
* @param array $args | |
* @SuppressWarnings(PHPMD.CamelCaseMethodName) This method overrides its parent | |
* @SuppressWarnings(PHPMD.UnusedFormalParameter) This method overrides its parent | |
*/ | |
// @codingStandardsIgnoreLine | |
public function start_lvl(&$output, $depth = 0, $args = []) | |
{ | |
// Depth | |
$indent = ($depth ? str_repeat("\t", $depth) : ''); | |
// Class | |
$class = ($depth == 1 ? '' : 'navbar-dropdown'); | |
// Output | |
$output .= $indent . '<ul class="' . $class . '">'; | |
} | |
/** | |
* @param $classes | |
* @param $item | |
* @param $args | |
* @param $depth | |
* @return array | |
* @SuppressWarnings(PHPMD.UnusedFormalParameter) This method overrides its parent | |
*/ | |
public function itemClasses($classes, $item, /** @noinspection PhpUnusedParameterInspection */ $args, $depth) | |
{ | |
return array_filter(array_map(function ($class) use ($depth, $args) { | |
switch ($class) { | |
case 'menu-item-has-children': | |
return 'has-dropdown is-hoverable'; | |
case 'menu-item': | |
return $args->theme_location == 'primary_navigation' ? 'navbar-item' : $class; | |
default: | |
return $class; | |
} | |
}, parent::cssClasses($classes, $item))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment