From 597b54bf84550242b7339e6e0dfdec91bda3f2e2 Mon Sep 17 00:00:00 2001 From: Constantine Nathanson Date: Tue, 23 Jul 2024 08:11:33 +0300 Subject: [PATCH] Add support for `defaultDisabled` parameter in `MetadataField` --- src/Api/Metadata/MetadataField.php | 38 +++++++++++++++++++++++-- tests/Unit/Admin/MetadataFieldsTest.php | 12 +++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/Api/Metadata/MetadataField.php b/src/Api/Metadata/MetadataField.php index 9dac0113..a061e7df 100644 --- a/src/Api/Metadata/MetadataField.php +++ b/src/Api/Metadata/MetadataField.php @@ -54,6 +54,11 @@ abstract class MetadataField extends Metadata */ protected $restrictions; + /** + * @var bool + */ + protected $defaultDisabled; + /** * The MetadataField constructor. * @@ -71,7 +76,16 @@ public function __construct($label) */ public function getPropertyKeys() { - return ['externalId', 'label', 'mandatory', 'defaultValue', 'type', 'validation', 'restrictions']; + return [ + 'externalId', + 'label', + 'mandatory', + 'defaultValue', + 'type', + 'validation', + 'restrictions', + 'defaultDisabled', + ]; } /** @@ -159,7 +173,7 @@ public function getMandatory() * * @param bool $mandatory A boolean indicating whether the field should be mandatory. */ - public function setMandatory($mandatory) + public function setMandatory($mandatory = true) { $this->mandatory = $mandatory; } @@ -203,4 +217,24 @@ public function setRestrictions($restrictions) { $this->restrictions = $restrictions; } + + /** + * Gets the value indicating whether the field should be disabled by default. + * + * @return bool + */ + public function isDefaultDisabled() + { + return $this->defaultDisabled; + } + + /** + * Sets the value indicating whether the field should be disabled by default. + * + * @param bool $defaultDisabled The value to set. + */ + public function setDefaultDisabled($defaultDisabled = true) + { + $this->defaultDisabled = $defaultDisabled; + } } diff --git a/tests/Unit/Admin/MetadataFieldsTest.php b/tests/Unit/Admin/MetadataFieldsTest.php index 1a160f3e..9f67d1c5 100644 --- a/tests/Unit/Admin/MetadataFieldsTest.php +++ b/tests/Unit/Admin/MetadataFieldsTest.php @@ -66,6 +66,8 @@ public function testCreateStringMetadataField() $stringMetadataField = new StringMetadataField(self::EXTERNAL_ID_STRING); $stringMetadataField->setExternalId(self::EXTERNAL_ID_STRING); $stringMetadataField->setRestrictions(["readonly_ui" => true]); + $stringMetadataField->setMandatory(false); + $stringMetadataField->setDefaultDisabled(); $mockAdminApi->addMetadataField($stringMetadataField); $lastRequest = $mockAdminApi->getMockHandler()->getLastRequest(); @@ -75,10 +77,12 @@ public function testCreateStringMetadataField() self::assertRequestFields( $lastRequest, [ - 'type' => MetadataFieldType::STRING, - 'external_id' => self::EXTERNAL_ID_STRING, - 'label' => self::EXTERNAL_ID_STRING, - 'restrictions' => ["readonly_ui" => true], + 'type' => MetadataFieldType::STRING, + 'external_id' => self::EXTERNAL_ID_STRING, + 'label' => self::EXTERNAL_ID_STRING, + 'mandatory' => false, + 'restrictions' => ["readonly_ui" => true], + 'default_disabled' => true, ] ); }