Open Journal Systems  3.3.0
Field.inc.php
1 <?php
14 namespace PKP\components\forms;
15 
16 abstract class Field {
18  public $component;
19 
21  public $name;
22 
24  public $label = '';
25 
27  public $description;
28 
30  public $tooltip;
31 
33  public $helpTopic;
34 
36  public $helpSection;
37 
39  public $groupId;
40 
42  public $isRequired = false;
43 
45  public $isMultilingual = false;
46 
48  public $value;
49 
51  public $default;
52 
61  public $showWhen;
62 
64  private $_requiredProperties = array('name', 'component');
65 
77  public function __construct($name, $args = array()) {
78  $this->name = $name;
79  foreach ($args as $key => $value) {
80  if (property_exists($this, $key)) {
81  $this->{$key} = $value;
82  }
83  }
84  }
85 
92  public function getConfig() {
93  if (!$this->validate()) {
94  fatalError('Form field configuration did not pass validation: ' . print_r($this, true));
95  }
96  $config = array(
97  'name' => $this->name,
98  'component' => $this->component,
99  'label' => $this->label,
100  );
101  if (isset($this->description)) {
102  $config['description'] = $this->description;
103  }
104  if (isset($this->tooltip)) {
105  $config['tooltip'] = $this->tooltip;
106  }
107  if (isset($this->helpTopic)) {
108  $config['helpTopic'] = $this->helpTopic;
109  if ($this->helpSection) {
110  $config['helpSection'] = $this->helpSection;
111  }
112  }
113  if (isset($this->groupId)) {
114  $config['groupId'] = $this->groupId;
115  }
116  if (isset($this->isRequired)) {
117  $config['isRequired'] = $this->isRequired;
118  }
119  if (isset($this->isMultilingual)) {
120  $config['isMultilingual'] = $this->isMultilingual;
121  }
122  if (isset($this->showWhen)) {
123  $config['showWhen'] = $this->showWhen;
124  }
125  if (isset($this->value)) {
126  $config['value'] = $this->value;
127  } elseif (isset($this->default)) {
128  $config['value'] = $this->default;
129  }
130  return $config;
131  }
132 
140  public function validate() {
141  foreach ($this->_requiredProperties as $property) {
142  if (!isset($this->{$property})) {
143  return false;
144  }
145  }
146  return true;
147  }
148 
161  public function getEmptyValue() {
162  return '';
163  }
164 }
PKP\components\forms\Field\$tooltip
$tooltip
Definition: Field.inc.php:45
PKP\components\forms
PKP\components\forms\Field\$value
$value
Definition: Field.inc.php:81
PKP\components\forms\Field\getConfig
getConfig()
Definition: Field.inc.php:134
PKP\components\forms\Field\$isMultilingual
$isMultilingual
Definition: Field.inc.php:75
PKP\components\forms\Field\$component
$component
Definition: Field.inc.php:21
PKP\components\forms\Field\$helpTopic
$helpTopic
Definition: Field.inc.php:51
PKP\components\forms\Field\validate
validate()
Definition: Field.inc.php:182
PKP\components\forms\Field\$helpSection
$helpSection
Definition: Field.inc.php:57
PKP\components\forms\Field\$name
$name
Definition: Field.inc.php:27
PKP\components\forms\Field
Definition: Field.inc.php:16
PKP\components\forms\Field\$default
$default
Definition: Field.inc.php:87
PKP\components\forms\Field\$isRequired
$isRequired
Definition: Field.inc.php:69
PKP\components\forms\Field\getEmptyValue
getEmptyValue()
Definition: Field.inc.php:203
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32
PKP\components\forms\Field\$showWhen
$showWhen
Definition: Field.inc.php:100
PKP\components\forms\Field\$description
$description
Definition: Field.inc.php:39
PKP\components\forms\Field\$groupId
$groupId
Definition: Field.inc.php:63
PKP\components\forms\Field\__construct
__construct($name, $args=array())
Definition: Field.inc.php:119
PKP\components\forms\Field\$label
$label
Definition: Field.inc.php:33