| Total Complexity | 5 |
| Total Lines | 84 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Browser extends TwillFormComponent |
||
| 8 | { |
||
| 9 | public $moduleName; |
||
| 10 | public $modules; |
||
| 11 | public $endpoints; |
||
| 12 | public $max; |
||
| 13 | public $note; |
||
| 14 | public $fieldNote; |
||
| 15 | public $browserNote; |
||
| 16 | public $itemLabel; |
||
| 17 | public $buttonOnTop; |
||
| 18 | public $wide; |
||
| 19 | public $sortable; |
||
| 20 | public $endpoint; |
||
| 21 | public $routePrefix; |
||
| 22 | public $params; |
||
| 23 | |||
| 24 | public function __construct( |
||
| 25 | $label, |
||
| 26 | $name = null, |
||
| 27 | $moduleName = null, |
||
| 28 | $modules = [], |
||
| 29 | $endpoints = [], |
||
| 30 | $endpoint = null, |
||
| 31 | $max = 1, |
||
| 32 | $note = null, |
||
| 33 | $fieldNote = null, |
||
| 34 | $browserNote = null, |
||
| 35 | $itemLabel = null, |
||
| 36 | $buttonOnTop = false, |
||
| 37 | $wide = false, |
||
| 38 | $sortable = true, |
||
| 39 | $routePrefix = null, |
||
| 40 | $params = [] |
||
| 41 | ) { |
||
| 42 | $name = $name ?? $moduleName; |
||
| 43 | parent::__construct($name, $label); |
||
| 44 | $this->name = $name; |
||
| 45 | $this->moduleName = $moduleName; |
||
| 46 | $this->modules = $modules; |
||
| 47 | $this->endpoints = $endpoints; |
||
| 48 | $this->endpoint = $endpoint; |
||
| 49 | $this->max = $max; |
||
| 50 | $this->note = $note; |
||
| 51 | $this->fieldNote = $fieldNote; |
||
| 52 | $this->browserNote = $browserNote; |
||
| 53 | $this->itemLabel = $itemLabel; |
||
| 54 | $this->buttonOnTop = $buttonOnTop; |
||
| 55 | $this->wide = $wide; |
||
| 56 | $this->sortable = $sortable; |
||
| 57 | $this->routePrefix = $routePrefix; |
||
| 58 | $this->params = $params; |
||
| 59 | |||
| 60 | $endpointsFromModules = isset($this->modules) ? collect($this->modules)->map(function ($module) { |
||
| 61 | return [ |
||
| 62 | 'label' => $module['label'] ?? ucfirst($module['name']), |
||
| 63 | 'value' => moduleRoute( |
||
| 64 | $module['name'], |
||
| 65 | $module['routePrefix'] ?? null, |
||
| 66 | 'browser', |
||
| 67 | $module['params'] ?? [], |
||
| 68 | false |
||
| 69 | ), |
||
| 70 | ]; |
||
| 71 | })->toArray() : null; |
||
| 72 | |||
| 73 | $this->endpoints = $this->endpoints ?? $endpointsFromModules ?? []; |
||
| 74 | $this->endpoint = $this->endpoint ?? (!empty($endpoints) ? null : moduleRoute( |
||
| 75 | $this->moduleName, |
||
| 76 | $this->routePrefix, |
||
| 77 | 'browser', |
||
| 78 | $this->params, |
||
| 79 | false |
||
| 80 | )); |
||
| 81 | |||
| 82 | $this->itemLabel = $this->itemLabel ?? strtolower($this->label); |
||
| 83 | |||
| 84 | $this->note = $this->note ?? |
||
| 85 | 'Add' . ($this->max > 1 ? " up to {$this->max} " . $itemLabel : ' one ' . Str::singular($this->itemLabel)); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function render() |
||
| 91 | } |
||
| 92 | } |
||
| 93 |