PluginProbe
Simple Analytics / trunk
Simple Analytics vtrunk
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / Settings / Tab.php

Tab.php in Simple Analytics trunk, at src/Settings/Tab.php

115 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics\Settings;
4
5 use SimpleAnalytics\Support\SvgIcon;
6
7 class Tab
8 {
9 use Concerns\HasDocs;
10 use Concerns\ManagesBlocks;
11
12 /**
13 * @readonly
14 * @var string
15 */
16 protected $name;
17
18 /**
19 * @readonly
20 * @var string
21 */
22 protected $slug;
23
24 /**
25 * @var \SimpleAnalytics\Support\SvgIcon|null
26 */
27 protected $icon;
28
29 /**
30 * @var string|null
31 */
32 protected $title;
33
34 /** @var Block[] */
35 protected $blocks = [];
36
37 public function __construct(string $name, string $slug)
38 {
39 $this->name = $name;
40 $this->slug = $slug;
41 }
42
43 public function getName(): string
44 {
45 return $this->name;
46 }
47
48 public function getSlug(): string
49 {
50 return $this->slug;
51 }
52
53 public function icon(SvgIcon $icon): self
54 {
55 $this->icon = $icon;
56
57 return $this;
58 }
59
60 public function getIcon(): ?SvgIcon
61 {
62 return $this->icon;
63 }
64
65 public function title(string $title): self
66 {
67 $this->title = $title;
68
69 return $this;
70 }
71
72 protected function addBlock(Block $block): self
73 {
74 $this->blocks[] = $block;
75 return $this;
76 }
77
78 public function getBlocks(): array
79 {
80 return $this->blocks;
81 }
82
83 public function render(): void
84 {
85 ?>
86 <div class="grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
87 <?php if (isset($this->title) || isset($this->description)): ?>
88 <div class="sm:col-span-4">
89 <?php if (isset($this->title)): ?>
90 <h1 class="text-sm font-medium leading-6 text-gray-900">
91 <?php echo esc_html($this->title); ?>
92 <?php if (isset($this->docs)): ?>
93 <a href="<?php echo esc_url($this->docs); ?>" target="_blank"
94 class="text-primary">(docs)</a>
95 <?php endif; ?>
96 </h1>
97 <?php endif; ?>
98 <?php if (isset($this->description)): ?>
99 <p class="mt-2 text-sm text-gray-500">
100 <?php echo esc_html($this->description); ?>
101 </p>
102 <?php endif; ?>
103 </div>
104 <?php endif; ?>
105
106 <?php foreach ($this->getBlocks() as $block): ?>
107 <div class="sm:col-span-4">
108 <?php $block->render(); ?>
109 </div>
110 <?php endforeach; ?>
111 </div>
112 <?php
113 }
114 }
115