Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SourceCodeValidator.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 use Magento\Framework\Validation\ValidationResultFactory;
14 
19 {
23  private $validationResultFactory;
24 
28  public function __construct(ValidationResultFactory $validationResultFactory)
29  {
30  $this->validationResultFactory = $validationResultFactory;
31  }
32 
37  {
38  $value = (string)$source->getSourceCode();
39 
40  if ('' === trim($value)) {
41  $errors[] = __('"%field" can not be empty.', ['field' => SourceItemInterface::SOURCE_CODE]);
42  } elseif (preg_match('/\s/', $value)) {
43  $errors[] = __('"%field" can not contain whitespaces.', ['field' => SourceItemInterface::SOURCE_CODE]);
44  } else {
45  $errors = [];
46  }
47  return $this->validationResultFactory->create(['errors' => $errors]);
48  }
49 }
__construct(ValidationResultFactory $validationResultFactory)
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23
__()
Definition: __.php:13
$value
Definition: gender.phtml:16
$errors
Definition: overview.phtml:9