/** * Validate minimum product qty value * * @return $this */ public function beforeSave() { parent::beforeSave(); $minQty = (int) $this->getValue() >= 0 ? (int) $this->getValue() : (int) $this->getOldValue(); $this->setValue((string) $minQty); return $this; }
/** * @return $this */ public function beforeSave() { if (is_array($this->getValue())) { $this->setValue(serialize($this->getValue())); } return parent::beforeSave(); }
/** * Validate specified value against frontend area * * @return $this */ public function beforeSave() { if ('' != $this->getValue()) { $design = clone $this->_design; $design->setDesignTheme($this->getValue(), \Magento\Framework\App\Area::AREA_FRONTEND); } return parent::beforeSave(); }
/** * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { if (!empty($this->getValue()) && !$this->_isRegexp($this->getValue())) { $this->messageManager->addNotice(__('Invalid regular expression: %value', ['value' => $this->getValue()])); $this->setValue(null); } return parent::beforeSave(); }
/** * Validate a domain name value * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { $value = $this->getValue(); if (!empty($value) && !$this->configValidator->isValid($value)) { $msg = __('Invalid cookie lifetime: ' . join('; ', $this->configValidator->getMessages())); throw new \Magento\Framework\Exception\LocalizedException($msg); } return parent::beforeSave(); }
/** * Validate expiration period value before saving * * @return $this */ public function beforeSave() { parent::beforeSave(); $expirationPeriod = (int) $this->getValue(); if ($expirationPeriod < 1) { $expirationPeriod = (int) $this->getOldValue(); } $this->setValue((string) $expirationPeriod); return $this; }
/** * Validate expiration period value before saving * * @return $this */ public function beforeSave() { parent::beforeSave(); $resetPasswordLinkExpirationPeriod = (int) $this->getValue(); if ($resetPasswordLinkExpirationPeriod < 1) { $resetPasswordLinkExpirationPeriod = (int) $this->getOldValue(); } $this->setValue((string) $resetPasswordLinkExpirationPeriod); return $this; }
public function beforeSave() { $value = (int) $this->getValue(); if ($value > self::MAX_LIFETIME) { throw new LocalizedException(__('Admin session lifetime must be less than or equal to 31536000 seconds (one year)')); } else { if ($value < self::MIN_LIFETIME) { throw new LocalizedException(__('Admin session lifetime must be greater than or equal to 60 seconds')); } } return parent::beforeSave(); }
/** * Cron settings after save * * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function beforeSave() { $active = $this->getData(self::XML_PATH_BAIDUPUSH_ACTIVE); $url = $this->getValue(); if (!empty($url)) { if (!preg_match('/http:\\/\\/[\\w.]+[\\w\\/]*[\\w.]*\\??[\\w=&\\+\\%]*/is', $url)) { throw new \Magento\Framework\Exception\LocalizedException(__($url . 'is not a valid URL')); } if (strpos($url, 'data.zz.baidu.com/urls') === false) { throw new \Magento\Framework\Exception\LocalizedException(__($url . 'is not a valid Baidu API URL')); } } elseif ($active) { throw new \Magento\Framework\Exception\LocalizedException(__('Baidu API URL should not be null')); } return parent::beforeSave(); }
/** * Validate ip addresses before save * * @return $this */ public function beforeSave() { $allowedIpsRaw = $this->getValue(); $noticeMsgArray = []; $allowedIpsArray = []; if (empty($allowedIpsRaw)) { return parent::beforeSave(); } $dataArray = explode(',', $allowedIpsRaw); foreach ($dataArray as $data) { if (filter_var(trim($data), FILTER_VALIDATE_IP)) { $allowedIpsArray[] = $data; } else { $noticeMsgArray[] = $data; } } $noticeMsg = implode(',', $noticeMsgArray); if (!empty($noticeMsgArray)) { $this->messageManager->addNotice(__(__('The following invalid values cannot be saved: %values', ['values' => $noticeMsg]))); } $this->setValue(implode(',', $allowedIpsArray)); return parent::beforeSave(); }