Esempio n. 1
0
 /**
  * @param \Magento\Bundle\Model\Option $value
  * @return void
  * @throws Zend_Validate_Exception
  * @throws \Exception
  */
 protected function validateRequiredFields($value)
 {
     $messages = [];
     $requiredFields = ['title' => $value->getTitle(), 'type' => $value->getType()];
     foreach ($requiredFields as $requiredField => $requiredValue) {
         if (!$this->notEmpty->isValid(trim($requiredValue))) {
             $messages[$requiredField] = __(InputException::REQUIRED_FIELD, ['fieldName' => $requiredField]);
         }
     }
     $this->_addMessages($messages);
 }
 /**
  * Adds validation rule for user password
  *
  * @param \Magento\Framework\Validator\DataObject $validator
  * @return \Magento\Framework\Validator\DataObject
  */
 public function addPasswordRules(\Magento\Framework\Validator\DataObject $validator)
 {
     $passwordNotEmpty = new NotEmpty();
     $passwordNotEmpty->setMessage(__('Password is required field.'), NotEmpty::IS_EMPTY);
     $minPassLength = self::MIN_PASSWORD_LENGTH;
     $passwordLength = new StringLength(['min' => $minPassLength, 'encoding' => 'UTF-8']);
     $passwordLength->setMessage(__('Your password must be at least %1 characters.', $minPassLength), \Zend_Validate_StringLength::TOO_SHORT);
     $passwordChars = new Regex('/[a-z].*\\d|\\d.*[a-z]/iu');
     $passwordChars->setMessage(__('Your password must include both numeric and alphabetic characters.'), \Zend_Validate_Regex::NOT_MATCH);
     $validator->addRule($passwordNotEmpty, 'password')->addRule($passwordLength, 'password')->addRule($passwordChars, 'password');
     return $validator;
 }