Commit | Line | Data |
---|---|---|
92f656cb TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | Copyright CiviCRM LLC. All rights reserved. | | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
10 | */ | |
11 | ||
12 | namespace Civi\WorkflowMessage; | |
13 | ||
14 | use Civi\Schema\Traits\ArrayFormatTrait; | |
15 | use Civi\Schema\Traits\BasicSpecTrait; | |
16 | use Civi\Schema\Traits\PhpDataTypeSpecTrait; | |
17 | use Civi\Schema\Traits\OptionsSpecTrait; | |
18 | ||
19 | class FieldSpec { | |
20 | ||
21 | // BasicSpecTrait: name, title, description | |
22 | use BasicSpecTrait; | |
23 | ||
24 | // PhpDataTypeSpecTrait: type, dataType, serialize, fkEntity | |
25 | use PhpDataTypeSpecTrait; | |
26 | ||
27 | // OptionsSpecTrait: options, optionsCallback | |
28 | use OptionsSpecTrait; | |
29 | ||
30 | // ArrayFormatTrait: toArray():array, loadArray($array) | |
31 | use ArrayFormatTrait; | |
32 | ||
33 | /** | |
34 | * @var bool|null | |
35 | */ | |
36 | public $required; | |
37 | ||
38 | /** | |
39 | * Allow this property to be used in alternative scopes, such as Smarty and TokenProcessor. | |
40 | * | |
41 | * @var array|null | |
42 | * Ex: ['Smarty' => 'smarty_name'] | |
43 | */ | |
44 | public $scope; | |
45 | ||
46 | /** | |
47 | * @return bool | |
48 | */ | |
49 | public function isRequired(): ?bool { | |
50 | return $this->required; | |
51 | } | |
52 | ||
53 | /** | |
54 | * @param bool|null $required | |
55 | * @return $this | |
56 | */ | |
57 | public function setRequired(?bool $required) { | |
58 | $this->required = $required; | |
59 | return $this; | |
60 | } | |
61 | ||
62 | /** | |
63 | * @return array|NULL | |
64 | */ | |
65 | public function getScope(): ?array { | |
66 | return $this->scope; | |
67 | } | |
68 | ||
69 | /** | |
70 | * Enable export/import in alternative scopes. | |
71 | * | |
72 | * @param string|array|NULL $scope | |
73 | * Ex: 'tplParams' | |
74 | * Ex: 'tplParams as foo_bar' | |
75 | * Ex: 'tplParams as contact_id, TokenProcessor as contactId' | |
76 | * Ex: ['tplParams' => 'foo_bar'] | |
77 | * @return $this | |
78 | */ | |
79 | public function setScope($scope) { | |
80 | if (is_array($scope)) { | |
81 | $this->scope = $scope; | |
82 | } | |
83 | else { | |
84 | $parts = explode(',', $scope); | |
85 | $this->scope = []; | |
86 | foreach ($parts as $part) { | |
87 | if (preg_match('/^\s*(\S+) as (\S+)\s*$/', $part, $m)) { | |
88 | $this->scope[trim($m[1])] = trim($m[2]); | |
89 | } | |
90 | else { | |
91 | $this->scope[trim($part)] = $this->getName(); | |
92 | } | |
93 | } | |
94 | } | |
95 | return $this; | |
96 | } | |
97 | ||
98 | } |