/
Create.php
92 lines (76 loc) · 2.33 KB
/
Create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
namespace Sterc\Formalicious\Processors\Mgr\Forms;
use MODX\Revolution\Processors\Model\CreateProcessor;
use Sterc\Formalicious\Model\FormaliciousForm;
class Create extends CreateProcessor
{
/**
* @access public.
* @var String.
*/
public $classKey = FormaliciousForm::class;
/**
* @access public.
* @var Array.
*/
public $languageTopics = ['formalicious:default'];
/**
* @access public.
* @var String.
*/
public $objectType = 'formalicious.form';
/**
* @access public.
* @return Mixed.
*/
public function initialize()
{
if (null === $this->getProperty('published')) {
$this->setProperty('published', 0);
}
if (null === $this->getProperty('saveform')) {
$this->setProperty('saveform', 0);
}
if (null === $this->getProperty('redirectto')) {
$this->setProperty('redirectto', 0);
}
if (null === $this->getProperty('fiaremail')) {
$this->setProperty('fiaremail', 0);
}
return parent::initialize();
}
/**
* @access public.
* @return Mixed.
*/
public function beforeSet()
{
if (empty($this->getProperty('published_from'))) {
$this->object->set('published_from', '0000-00-00 00:00:00');
}
if (empty($this->getProperty('published_till'))) {
$this->object->set('published_till', '0000-00-00 00:00:00');
}
return parent::beforeSet();
}
/**
* @access public.
* @return Mixed.
*/
public function beforeSave()
{
$name = $this->getProperty('name');
$query = ['name' => $name];
if (empty($name)) {
$this->addFieldError('name', $this->modx->lexicon('formalicious.form_err_ns_name'));
} else if ($this->doesAlreadyExist($query)) {
$this->addFieldError('name', $this->modx->lexicon('formalicious.form_err_ae'));
}
foreach (explode(',', $this->getProperty('posthooks')) as $hook) {
if (in_array($hook, (array) $this->modx->formalicious->config['disallowed_hooks'], true)) {
$this->addFieldError('posthooks', $this->modx->lexicon('formalicious.form_err_posthooks'));
}
}
return parent::beforeSave();
}
}