301]; /** @var array */ protected $_redirectStatuses = [ 300 => '300 Multiple Choices', 301 => '301 Moved Permanently', 302 => '302 Moved temporarily', 303 => '303 See Other', 307 => '307 Temporary Redirect', ]; /** * @return App_Redirection_Admin_Obj */ protected function _getDataObj() { if (null === $this->_dataObj) { $this->_dataObj = new App_Redirection_Admin_Obj(); } return $this->_dataObj; } /** * @return App_Redirection_Admin_Form_Abstract|Qs_Form */ protected function _initElements() { $this->addElement('text', 'source', ['label' => 'Source Alias', 'required' => true]); $this->addElement('text', 'destination', ['label' => 'Destination Alias', 'required' => true]); $this->addElement( 'select', 'status', ['label' => 'Redirect Status', 'multiOptions' => $this->_redirectStatuses] ); $this->addFormRule([$this, 'validateForm']); return $this; } /** * @param array $data * @return array|bool */ public function validateForm(array $data) { $errors = []; $page = Qs_SiteMap::getPage($data['source']); if (is_array($page) && !empty($page)) { $errors['source'] = 'Source Alias already exists on the website'; } else if ($this->_getDataObj()->isUnique('source', $data['source'])) { $errors['source'] = 'Redirect for this Source Alias already exists'; } if (Qs_SiteMap::NOT_FOUND == Qs_SiteMap::getPage($data['destination'])) { $errors['destination'] = 'Destination Alias doesn\'t exist on the website'; } return (!$errors) ? true : $errors; } }