Beispiel #1
0
 /**
  * Validate customer attribute values.
  * For existing customer password + confirmation will be validated only when password is set
  * (i.e. its change is requested)
  *
  * @return bool|string[]
  */
 public function validate()
 {
     /** @var $validator \Magento\Framework\Validator\Object */
     $validator = $this->_validatorObject->create();
     $this->validationRules->addUserInfoRules($validator);
     if (!$validator->isValid($this)) {
         return $validator->getMessages();
     }
     return true;
 }
Beispiel #2
0
 /**
  * Add validation rules for particular fields
  *
  * @return \Zend_Validate_Interface
  */
 protected function _getValidationRulesBeforeSave()
 {
     $userNameNotEmpty = new \Zend_Validate_NotEmpty();
     $userNameNotEmpty->setMessage(__('User Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $firstNameNotEmpty = new \Zend_Validate_NotEmpty();
     $firstNameNotEmpty->setMessage(__('First Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $lastNameNotEmpty = new \Zend_Validate_NotEmpty();
     $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $emailValidity = new \Zend_Validate_EmailAddress();
     $emailValidity->setMessage(__('Please enter a valid email.'), \Zend_Validate_EmailAddress::INVALID);
     /** @var $validator \Magento\Framework\Validator\Object */
     $validator = $this->_validatorObject->create();
     $validator->addRule($userNameNotEmpty, 'username')->addRule($firstNameNotEmpty, 'firstname')->addRule($lastNameNotEmpty, 'lastname')->addRule($emailValidity, 'email');
     if ($this->_willSavePassword()) {
         $this->_addPasswordValidation($validator);
     }
     return $validator;
 }
Beispiel #3
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\Validator\ObjectFactory $validatorCompositeFactory
  * @param \Magento\GoogleAdwords\Model\Validator\Factory $validatorFactory
  * @param \Magento\Framework\Model\Resource\AbstractResource $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  * @param array $data
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\Validator\ObjectFactory $validatorCompositeFactory, \Magento\GoogleAdwords\Model\Validator\Factory $validatorFactory, \Magento\Framework\Model\Resource\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $config, $resource, $resourceCollection, $data);
     $this->_validatorFactory = $validatorFactory;
     $this->_validatorComposite = $validatorCompositeFactory->create();
 }