directoryHelper = $directoryHelper; $stringHelper = $stringHelper ?? \Magento\Framework\App\ObjectManager::getInstance()->get(StringUtils::class); parent::__construct( $localeDate, $logger, $attribute, $localeResolver, $value, $entityTypeCode, $isAjax, $stringHelper ); } /** * Validate postal/zip code * * Return true and skip validation if country zip code is optional * * @param array|null|string $value * @return array|bool */ public function validateValue($value) { $attribute = $this->getAttribute(); $label = __($attribute->getStoreLabel()); $countryId = $this->getExtractedData('country_id'); if ($this->directoryHelper->isZipCodeOptional($countryId)) { return true; } $errors = []; if (empty($value) && $value !== '0') { $errors[] = __('"%1" is a required value.', $label); } $errors = $this->validateLength($value, $attribute, $errors); $result = $this->_validateInputRule($value); if ($result !== true) { $errors = array_merge($errors, $result); } if (count($errors) == 0) { return true; } return $errors; } }