Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StockIdValidator.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 = (int)$link->getStockId();
39 
40  if (!$value) {
41  $errors[] = __('"%field" can not be empty.', ['field' => StockSourceLinkInterface::STOCK_ID]);
42  } else {
43  $errors = [];
44  }
45 
46  return $this->validationResultFactory->create(['errors' => $errors]);
47  }
48 }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16
$errors
Definition: overview.phtml:9