1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\BootstrapBundle\Twig\Extension\Component; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Abstract nav Twig extension. |
18
|
|
|
* |
19
|
|
|
* @author webeweb <https://github.com/webeweb/> |
20
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
21
|
|
|
* @abstract |
22
|
|
|
*/ |
23
|
|
|
abstract class AbstractNavTwigExtension extends AbstractTwigExtension { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Displays a Bootstrap nav item. |
27
|
|
|
* |
28
|
|
|
* @param string|null $item The item. |
29
|
|
|
* @return string Returns the Bootstrap nav item. |
30
|
|
|
*/ |
31
|
|
|
private function bootstrapNav(?string $item): string { |
32
|
|
|
return static::coreHTMLElement("li", $item, ["role" => "presentation"]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Displays a Bootstrap navs. |
37
|
|
|
* |
38
|
|
|
* @param array $items The items. |
39
|
|
|
* @param string|null $class The class. |
40
|
|
|
* @param bool|null $stacked Stacked ? |
41
|
|
|
* @return string Returns the Bootstrap nav. |
42
|
|
|
*/ |
43
|
|
|
protected function bootstrapNavs(array $items, ?string $class, ?bool $stacked): string { |
44
|
|
|
|
45
|
|
|
$attributes = []; |
46
|
|
|
|
47
|
|
|
$attributes["class"][] = "nav"; |
48
|
|
|
$attributes["class"][] = $class; |
49
|
|
|
$attributes["class"][] = true === $stacked ? "nav-stacked" : null; |
50
|
|
|
|
51
|
|
|
$innerHTML = []; |
52
|
|
|
foreach ($items as $current) { |
53
|
|
|
$innerHTML[] = $this->bootstrapNav($current); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return static::coreHTMLElement("ul", "\n" . implode("\n", $innerHTML) . "\n", $attributes); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|