| Total Complexity | 8 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | trait WithoutModelAttribute |
||
| 10 | { |
||
| 11 | private string $autoIdPrefix = ''; |
||
| 12 | private array $attributes = []; |
||
| 13 | private string $id = ''; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The prefix to the automatically generated widget IDs. |
||
| 17 | * |
||
| 18 | * @param string $value |
||
| 19 | * |
||
| 20 | * @return static |
||
| 21 | */ |
||
| 22 | 3 | public function autoIdPrefix(string $value): self |
|
| 23 | { |
||
| 24 | 3 | $new = clone $this; |
|
| 25 | 3 | $new->autoIdPrefix = $value; |
|
| 26 | 3 | return $new; |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The HTML attributes. The following special options are recognized. |
||
| 31 | * |
||
| 32 | * @param array $value |
||
| 33 | * |
||
| 34 | * @return static |
||
| 35 | * |
||
| 36 | * See {@see \Yiisoft\Html\Html::renderTagAttributes()} for details on how attributes are being rendered. |
||
| 37 | */ |
||
| 38 | 18 | public function attributes(array $value): self |
|
| 39 | { |
||
| 40 | 18 | $new = clone $this; |
|
| 41 | 18 | $new->attributes = $value; |
|
| 42 | 18 | return $new; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Set the ID of the widget. |
||
| 47 | * |
||
| 48 | * @param string $id |
||
| 49 | * |
||
| 50 | * @return static |
||
| 51 | * |
||
| 52 | * @link https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute |
||
| 53 | */ |
||
| 54 | 3 | public function id(string $id): self |
|
| 55 | { |
||
| 56 | 3 | $new = clone $this; |
|
| 57 | 3 | $new->id = $id; |
|
| 58 | 3 | return $new; |
|
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Generates a unique ID for the attribute. |
||
| 63 | * |
||
| 64 | * @return string |
||
| 65 | */ |
||
| 66 | 27 | protected function getId(): string |
|
| 67 | { |
||
| 68 | 27 | return $this->id = $this->id !== '' ? $this->id : Html::generateId($this->autoIdPrefix); |
|
| 69 | } |
||
| 70 | |||
| 71 | 27 | protected function getName(): string |
|
| 80 | } |
||
| 81 | } |
||
| 82 |