create custom exceptions
This commit is contained in:
parent
7a751e92bf
commit
43be624bf6
5 changed files with 127 additions and 16 deletions
|
@ -16,6 +16,8 @@
|
|||
declare(strict_types = 1);
|
||||
|
||||
use CRM_Twingle_ExtensionUtil as E;
|
||||
use CRM_Twingle_Exceptions_ProfileException as ProfileException;
|
||||
use CRM_Twingle_Exceptions_ProfileValidationError as ProfileValidationError;
|
||||
|
||||
/**
|
||||
* Form controller class
|
||||
|
@ -633,23 +635,33 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
*/
|
||||
public function postProcess() {
|
||||
$values = $this->exportValues();
|
||||
if (in_array($this->_op, ['create', 'edit', 'copy'])) {
|
||||
if (empty($values['name'])) {
|
||||
$values['name'] = 'default';
|
||||
}
|
||||
$this->profile->setName($values['name']);
|
||||
foreach ($this->profile->getData() as $element_name => $value) {
|
||||
if ($element_name == 'newsletter_double_opt_in') {
|
||||
$values[$element_name] = (int) isset($values[$element_name]);
|
||||
try {
|
||||
if (in_array($this->_op, ['create', 'edit', 'copy'])) {
|
||||
if (empty($values['name'])) {
|
||||
$values['name'] = 'default';
|
||||
}
|
||||
if (isset($values[$element_name])) {
|
||||
$this->profile->setAttribute($element_name, $values[$element_name]);
|
||||
$this->profile->setName($values['name']);
|
||||
foreach ($this->profile->getData() as $element_name => $value) {
|
||||
if ($element_name == 'newsletter_double_opt_in') {
|
||||
$values[$element_name] = (int) isset($values[$element_name]);
|
||||
}
|
||||
if (isset($values[$element_name])) {
|
||||
$this->profile->setAttribute($element_name, $values[$element_name]);
|
||||
}
|
||||
}
|
||||
$this->profile->saveProfile();
|
||||
}
|
||||
$this->profile->saveProfile();
|
||||
}
|
||||
elseif ($this->_op == 'delete') {
|
||||
$this->profile->deleteProfile();
|
||||
elseif ($this->_op == 'delete') {
|
||||
$this->profile->deleteProfile();
|
||||
}
|
||||
} catch (ProfileException $e) {
|
||||
Civi::log()->error($e->getLogMessage());
|
||||
CRM_Core_Session::setStatus(
|
||||
E::ts('Error'),
|
||||
$e->getMessage(),
|
||||
'error',
|
||||
['unique' => TRUE]
|
||||
);
|
||||
}
|
||||
parent::postProcess();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue