Skip to content

Commit

Permalink
Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Nares committed Jul 19, 2023
1 parent b4c2731 commit ad3faa1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions modules/creation/adding-configuration-page-modern.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ use PrestaShop\PrestaShop\Core\ConfigurationInterface;
final class DemoConfigurationTextDataConfiguration implements DataConfigurationInterface
{
public const DEMO_SYMFONY_FORM_SIMPLE_TEXT_TYPE = 'DEMO_SYMFONY_FORM_SIMPLE_TEXT_TYPE';
public const CONFIG_MAXLENGTH = 32;
/**
* @var ConfigurationInterface
Expand Down Expand Up @@ -186,10 +187,18 @@ final class DemoConfigurationTextDataConfiguration implements DataConfigurationI
*/
public function updateConfiguration(array $configuration): array
{
$this->configuration->set(static::DEMO_SYMFONY_FORM_SIMPLE_TEXT_TYPE, $configuration['config_text']);
$errors = [];
if($this->validateConfiguration($configuration)){
if(strlen($configuration['config_text']) <= static::CONFIG_MAXLENGTH){
$this->configuration->set(static::DEMO_SYMFONY_FORM_SIMPLE_TEXT_TYPE, $configuration['config_text']);
} else {
$errors[] = "DEMO_SYMFONY_FORM_SIMPLE_TEXT_TYPE value is too long";
}
}
/* Errors are returned here. */
return [];
return $errors;
}
/**
Expand All @@ -201,7 +210,7 @@ final class DemoConfigurationTextDataConfiguration implements DataConfigurationI
*/
public function validateConfiguration(array $configuration): bool
{
return true;
return isset($configuration['config_text']);
}
}
```
Expand Down

0 comments on commit ad3faa1

Please sign in to comment.