From a9df17e6a8db67612f53bef6ce0c849bbf7140c6 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Mon, 25 Sep 2023 16:32:20 +0200 Subject: [PATCH] Element // fix attributesForView to return correct "disabled"-state in case the parent is disabled. View\FormRow // add new selector "form-row--is-disabled". --- src/Element/Element.php | 1 + src/View/FormRow.php | 3 +++ tests/phpunit/Unit/View/FormTest.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/Element/Element.php b/src/Element/Element.php index 94cb885..c33b96c 100644 --- a/src/Element/Element.php +++ b/src/Element/Element.php @@ -150,6 +150,7 @@ public function attributesForView(): array $id = $parentAttributes['id']; $name = $parentAttributes['name']; + $attributes['disabled'] = $this->isDisabled(); $attributes['id'] = $id . '_' . $attributes['id']; $attributes['name'] = $name . '[' . $attributes['name'] . ']'; } diff --git a/src/View/FormRow.php b/src/View/FormRow.php index 5c4df21..6486af0 100644 --- a/src/View/FormRow.php +++ b/src/View/FormRow.php @@ -83,6 +83,9 @@ public function render(ElementInterface $element): string if ($errors !== '') { $rowAttributes['class'] .= ' form-row--has-errors'; } + if ($element->isDisabled()) { + $rowAttributes['class'] .= 'form-row--is-disabled'; + } if ($element->type() === 'hidden') { $rowAttributes['class'] .= ' hidden'; } diff --git a/tests/phpunit/Unit/View/FormTest.php b/tests/phpunit/Unit/View/FormTest.php index 1b1228f..3e1a4e9 100644 --- a/tests/phpunit/Unit/View/FormTest.php +++ b/tests/phpunit/Unit/View/FormTest.php @@ -56,6 +56,8 @@ public function testRender(): void ->andReturn('text'); $element_stub->allows('attributesForView') ->andReturn([]); + $element_stub->allows('isDisabled') + ->andReturnFalse(); $form_stub = Mockery::mock(FormInterface::class, ElementInterface::class, CollectionElementInterface::class); $form_stub->allows('name')