Skip to content

Commit

Permalink
Add support for defaultDisabled parameter in MetadataField
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed Jul 23, 2024
1 parent ab1b9cb commit 597b54b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
38 changes: 36 additions & 2 deletions src/Api/Metadata/MetadataField.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ abstract class MetadataField extends Metadata
*/
protected $restrictions;

/**
* @var bool
*/
protected $defaultDisabled;

/**
* The MetadataField constructor.
*
Expand All @@ -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',
];
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
12 changes: 8 additions & 4 deletions tests/Unit/Admin/MetadataFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
]
);
}
Expand Down

0 comments on commit 597b54b

Please sign in to comment.