| 1 | <?php |
||
| 21 | trait TabTrait |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Render tab header from an array. |
||
| 25 | * |
||
| 26 | * @param array $tabs |
||
| 27 | * @param string $active |
||
| 28 | * |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | 39 | public function tab(array $tabs, $active) |
|
| 32 | { |
||
| 33 | $defaultTab = [ |
||
| 34 | 39 | 'title' => '', |
|
| 35 | 'prefix' => '', |
||
| 36 | 'active' => false, |
||
| 37 | 'url' => '', |
||
| 38 | ]; |
||
| 39 | |||
| 40 | 39 | $output = '<ul class="nav nav-tabs">'; |
|
| 41 | 39 | foreach ($tabs as $tab) { |
|
| 42 | 39 | $tab = array_replace($defaultTab, $tab); |
|
| 43 | |||
| 44 | 39 | $output .= '<li role="presentation" ' . $this->tabElementActive($tab, $active) . '>'; |
|
| 45 | 39 | $output .= $this->tabElementTitle($tab); |
|
| 46 | 39 | $output .= '</li>'; |
|
| 47 | } |
||
| 48 | 39 | $output .= '</ul>'; |
|
| 49 | |||
| 50 | 39 | return $output; |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Whether or not the tab element is active. |
||
| 55 | * |
||
| 56 | * @param array $tab |
||
| 57 | * @param string $active |
||
| 58 | * |
||
| 59 | * @return string |
||
| 60 | */ |
||
| 61 | 39 | protected function tabElementActive($tab, $active) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * Generate the content of a tab element. |
||
| 68 | * |
||
| 69 | * @param array $tab |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | 39 | protected function tabElementTitle($tab) |
|
| 79 | } |
||
| 80 |