| 1: | <?php |
| 2: | |
| 3: | declare(strict_types=1); |
| 4: | |
| 5: | namespace Atk4\Ui; |
| 6: | |
| 7: | class Breadcrumb extends Lister |
| 8: | { |
| 9: | public $ui = 'breadcrumb'; |
| 10: | |
| 11: | public $defaultTemplate = 'breadcrumb.html'; |
| 12: | |
| 13: | |
| 14: | public $path = []; |
| 15: | |
| 16: | |
| 17: | public $dividerClass = 'right angle icon'; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | public function addCrumb($section = null, $link = null) |
| 28: | { |
| 29: | if (is_array($link)) { |
| 30: | $link = $this->url($link); |
| 31: | } |
| 32: | $this->path[] = ['section' => $section, 'link' => $link, 'divider' => $this->dividerClass]; |
| 33: | |
| 34: | return $this; |
| 35: | } |
| 36: | |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | |
| 43: | public function popTitle() |
| 44: | { |
| 45: | $title = array_pop($this->path); |
| 46: | $this->set($title['section'] ?? ''); |
| 47: | |
| 48: | return $this; |
| 49: | } |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | public function addCrumbReverse($section = null, $link = null) |
| 60: | { |
| 61: | array_unshift($this->path, ['section' => $section, 'link' => $link]); |
| 62: | |
| 63: | return $this; |
| 64: | } |
| 65: | |
| 66: | #[\Override] |
| 67: | protected function renderView(): void |
| 68: | { |
| 69: | $this->setSource($this->path); |
| 70: | |
| 71: | parent::renderView(); |
| 72: | } |
| 73: | } |
| 74: | |