From 7f50ea14149e24d34ebc975aac384bc0e8a87ad9 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Mon, 25 Nov 2024 10:28:41 +1300 Subject: [PATCH] FIX Avoid infinite recursive loop with attributes in schemadata (#312) --- src/StringTagField.php | 13 ------------- src/TagField.php | 1 - templates/SilverStripe/TagField/TagField.ss | 2 +- tests/StringTagFieldTest.php | 7 ------- tests/TagFieldTest.php | 9 ++------- 5 files changed, 3 insertions(+), 29 deletions(-) diff --git a/src/StringTagField.php b/src/StringTagField.php index 81abe03..b994b19 100644 --- a/src/StringTagField.php +++ b/src/StringTagField.php @@ -197,19 +197,6 @@ protected function formatOptions($fieldValue) return $formattedValue; } - /** - * When not used in a React form factory context, this adds the schema data to SilverStripe template - * rendered attributes lists - * - * @return array - */ - public function getAttributes() - { - $attributes = parent::getAttributes(); - $attributes['data-schema'] = json_encode($this->getSchemaData()); - return $attributes; - } - /** * @return string */ diff --git a/src/TagField.php b/src/TagField.php index 317635c..10fb9be 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -381,7 +381,6 @@ public function getAttributes() [ 'name' => $name, 'style' => 'width: 100%', - 'data-schema' => json_encode($this->getSchemaData()), ] ); } diff --git a/templates/SilverStripe/TagField/TagField.ss b/templates/SilverStripe/TagField/TagField.ss index 01f51a5..51c8f91 100644 --- a/templates/SilverStripe/TagField/TagField.ss +++ b/templates/SilverStripe/TagField/TagField.ss @@ -1 +1 @@ -
+
diff --git a/tests/StringTagFieldTest.php b/tests/StringTagFieldTest.php index 4dcd73f..1a766c2 100755 --- a/tests/StringTagFieldTest.php +++ b/tests/StringTagFieldTest.php @@ -132,13 +132,6 @@ public function testGetSchemaDataDefaults() $this->assertStringContainsString('suggest', $schema['optionUrl']); } - public function testSchemaIsAddedToAttributes() - { - $field = new StringTagField('TestField'); - $attributes = $field->getAttributes(); - $this->assertNotEmpty($attributes['data-schema']); - } - public function testPerformReadonlyTransformation() { $field = new StringTagField('Tags'); diff --git a/tests/TagFieldTest.php b/tests/TagFieldTest.php index faf985f..0513b61 100755 --- a/tests/TagFieldTest.php +++ b/tests/TagFieldTest.php @@ -413,6 +413,8 @@ public function testReadonlyTransformation() $field = new TagField('Tags', '', TagFieldTestBlogTag::get()); $field->setTitleField('Title'); $field->setValue(['Tag1']); + $form = new Form(); + $field->setForm($form); // When not read only (and not lazy-loading) all source options are returned $htmlText = $field->Field(); @@ -482,13 +484,6 @@ public function testGetSchemaDataDefaults() $this->assertStringContainsString('suggest', $schema['optionUrl']); } - public function testSchemaIsAddedToAttributes() - { - $field = new TagField('TestField'); - $attributes = $field->getAttributes(); - $this->assertNotEmpty($attributes['data-schema']); - } - /** * @param array $options * @param string $title