12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace crmeb\form\components;
- use crmeb\form\BuildInterface;
- class Tabs implements BuildInterface
- {
-
- const NAME = 'tabs';
-
- protected $rule = [
- 'options' => []
- ];
-
- public function __construct(array $options = [])
- {
- $this->rule['options'] = $options;
- }
-
- public function option(string $label, array $components = [])
- {
- $this->rule['options'][] = ['label' => $label, 'componentsModel' => $components];
- return $this;
- }
-
- public function toArray(): array
- {
- $this->rule['name'] = self::NAME;
- $options = [];
- foreach ($this->rule['options'] as $option) {
- $data = ['label' => $option['label'], 'componentsModel' => []];
- foreach ($option['componentsModel'] as $item) {
- if ($item instanceof BuildInterface) {
- $data['componentsModel'][] = $item->toArray();
- }
- }
- $options[] = $data;
- }
- $this->rule['options'] = $options;
- return $this->rule;
- }
- }
|