Passed
Push — developer ( eeb773...44af72 )
by Radosław
17:47
created

Vtiger_Basic_InventoryField::getConfigField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * Inventory Basic Field Class.
5
 *
6
 * @package   InventoryField
7
 *
8
 * @copyright YetiForce S.A.
9
 * @license   YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 * @author    Radosław Skrzypczak <[email protected]>
12
 */
13
class Vtiger_Basic_InventoryField extends \App\Base
14
{
15
	/**
16
	 * Field visible everywhere.
17
	 */
18
	private const FIELD_VISIBLE_EVERYWHERE = 0;
19
	/**
20
	 * Field visible in detail view.
21
	 */
22
	private const FIELD_VISIBLE_IN_DETAIL = 2;
23
	/**
24
	 * Field hidden.
25
	 */
26
	private const FIELD_HIDDEN = 5;
27
	/**
28
	 * Field read-only.
29
	 */
30
	private const FIELD_READONLY = 10;
31
32
	protected $columnName = '';
33
	protected $moduleName = '';
34
35
	protected $type;
36
	protected $colSpan = 10;
37
	protected $defaultValue = '';
38
	protected $params = [];
39
	protected $dbType = 'string';
40
	protected $customColumn = [];
41
	protected $summationValue = false;
42
	protected $onlyOne = true;
43
	protected $displayType = self::FIELD_VISIBLE_EVERYWHERE;
44
	protected $displayTypeBase = [
45
		self::FIELD_VISIBLE_EVERYWHERE => 'LBL_DISPLAYTYPE_ALL',
46
		self::FIELD_VISIBLE_IN_DETAIL => 'LBL_DISPLAYTYPE_ONLY_DETAIL',
47
		self::FIELD_HIDDEN => 'LBL_DISPLAYTYPE_HIDDEN',
48
		self::FIELD_READONLY => 'LBL_DISPLAYTYPE_READONLY'
49
	];
50
	protected $blocks = [1];
51
	protected $fieldDataType = 'inventory';
52
	protected $maximumLength = 255;
53
	protected $defaultLabel = '';
54
	protected $purifyType = '';
55
	protected $customPurifyType = [];
56
	protected $customMaximumLength = [];
57
	/** @var array Default values for custom fields */
58
	protected $customDefault = [];
59
	/** @var bool Field is synchronized */
60
	protected $sync = false;
61
	/** @var array List of changes */
62
	protected $changes = [];
63
64
	/**
65
	 * Gets inventory field instance.
66
	 *
67 2
	 * @param string      $moduleName
68
	 * @param string|null $type
69 2
	 *
70 2
	 * @throws \App\Exceptions\AppException
71 2
	 *
72
	 * @return self
73 2
	 */
74 2
	public static function getInstance(string $moduleName, ?string $type = 'Basic')
75 2
	{
76 2
		$cacheName = "$moduleName:$type";
77
		if (\App\Cache::has(__METHOD__, $cacheName)) {
78 2
			$instance = \App\Cache::get(__METHOD__, $cacheName);
79
		} else {
80
			$className = Vtiger_Loader::getComponentClassName('InventoryField', $type, $moduleName);
81
			$instance = new $className();
82
			$instance->setModuleName($moduleName);
83
			\App\Cache::save(__METHOD__, $cacheName, $instance);
84
		}
85
		return clone $instance;
86 2
	}
87
88 2
	/**
89
	 * Function returns module name.
90
	 *
91
	 * @return string
92
	 */
93
	public function getModuleName(): string
94
	{
95
		return $this->moduleName;
96
	}
97
98 2
	/**
99
	 * Function to get the Id.
100 2
	 *
101 2
	 * @return int Field ID
102
	 */
103
	public function getId(): int
104
	{
105
		return (int) $this->get('id');
106
	}
107
108
	/**
109
	 * Sets module name.
110
	 *
111
	 * @param string $moduleName
112
	 *
113
	 * @return \Vtiger_Basic_InventoryField
114
	 */
115
	public function setModuleName(string $moduleName): self
116
	{
117
		$this->moduleName = $moduleName;
118
		return $this;
119
	}
120
121
	/**
122
	 * Getting onlyOne field.
123
	 *
124
	 * @return bool
125
	 */
126
	public function isOnlyOne()
127
	{
128
		return $this->onlyOne;
129
	}
130
131
	public function getBlocks()
132
	{
133
		return $this->blocks;
134
	}
135
136
	/**
137
	 * Getting database-type of field.
138 2
	 *
139
	 * @return string|yii\db\ColumnSchemaBuilder dbType
140 2
	 */
141 2
	public function getDBType()
142
	{
143 2
		$columnCriteria = $this->dbType;
144 2
		if (\is_array($columnCriteria)) {
0 ignored issues
show
introduced by
The condition is_array($columnCriteria) is always false.
Loading history...
145
			[$type, $length, $default, $unsigned] = array_pad($columnCriteria, 4, null);
146
			$columnCriteria = \App\Db::getInstance()->getSchema()->createColumnSchemaBuilder($type, $length);
147
			if (null !== $default) {
148
				$columnCriteria->defaultValue($default);
149
			}
150
			if (null !== $unsigned) {
151
				$columnCriteria->unsigned();
152
			}
153
		}
154
155
		return $columnCriteria;
156
	}
157 2
158
	/**
159 2
	 * Gets value for save.
160
	 *
161
	 * @param array  $item
162
	 * @param bool   $userFormat
163
	 * @param string $column
164
	 *
165
	 * @return mixed
166
	 */
167
	public function getValueForSave(array $item, bool $userFormat = false, string $column = null)
168
	{
169
		if (null === $column) {
170
			$column = $this->getColumnName();
171
		}
172
		$value = $item[$column] ?? null;
173
		return $userFormat ? $this->getDBValue($value) : $value;
174
	}
175
176
	/**
177
	 * Getting all params field.
178
	 *
179
	 * @return array
180
	 */
181
	public function getParams()
182
	{
183
		return $this->params;
184
	}
185
186
	/**
187
	 * Get params value.
188
	 *
189
	 * @return array
190
	 */
191
	public function getParamsConfig()
192
	{
193
		return $this->get('params') ? \App\Json::decode($this->get('params')) : [];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('param...et('params')) : array() also could return the type string which is incompatible with the documented return type array.
Loading history...
194
	}
195
196
	/**
197
	 * Get the configuration parameter value for the specified key.
198
	 *
199
	 * @param string $key
200
	 *
201
	 * @return mixed
202
	 */
203
	public function getParamConfig(string $key)
204
	{
205
		return $this->getParamsConfig()[$key] ?? null;
206
	}
207
208
	/**
209
	 * Getting all values display Type.
210
	 *
211
	 * @return array
212
	 */
213
	public function displayTypeBase()
214
	{
215
		return $this->displayTypeBase;
216
	}
217
218
	/**
219
	 * Gets display type.
220
	 *
221
	 * @return int
222
	 */
223
	public function getDisplayType(): int
224
	{
225
		return $this->has('displaytype') ? $this->get('displaytype') : $this->displayType;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->has('displ...') : $this->displayType could return the type null which is incompatible with the type-hinted return integer. Consider adding an additional type-check to rule them out.
Loading history...
226
	}
227
228
	public function getColSpan()
229
	{
230
		return $this->has('colspan') ? $this->get('colspan') : $this->colSpan;
231
	}
232
233
	public function getRangeValues()
234
	{
235
		return $this->maximumLength;
236
	}
237
238
	/**
239
	 * Get template name for edit.
240
	 *
241
	 * @return string
242
	 */
243
	public function getEditTemplateName()
244
	{
245
		return 'inventoryTypes/Base.tpl';
246
	}
247 1
248
	/**
249 1
	 * Getting template name.
250
	 *
251
	 * @param string $view
252
	 * @param string $moduleName
253
	 *
254
	 * @return string templateName
255
	 */
256
	public function getTemplateName($view, $moduleName)
257 2
	{
258
		$tpl = $view . $this->type . '.tpl';
259 2
		$filename = 'layouts' . DIRECTORY_SEPARATOR . \App\Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
260
		if (is_file($filename)) {
261
			return $tpl;
262
		}
263
		$filename = 'layouts' . DIRECTORY_SEPARATOR . \App\Layout::getActiveLayout() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
264
		if (is_file($filename)) {
265
			return $tpl;
266
		}
267 2
		$filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
268
		if (is_file($filename)) {
269 2
			return $tpl;
270
		}
271
		$filename = 'layouts' . DIRECTORY_SEPARATOR . Vtiger_Viewer::getDefaultLayoutName() . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'Vtiger' . DIRECTORY_SEPARATOR . 'inventoryfields' . DIRECTORY_SEPARATOR . $tpl;
272 2
		if (is_file($filename)) {
273
			return $tpl;
274 2
		}
275
		return $view . 'Base' . '.tpl';
276
	}
277 1
278
	/**
279 1
	 * Getting default label.
280
	 *
281
	 * @return string defaultLabel
282
	 */
283
	public function getDefaultLabel()
284
	{
285
		return $this->defaultLabel;
286
	}
287
288
	/**
289
	 * Getting field type.
290
	 *
291
	 * @return string
292
	 */
293
	public function getType()
294
	{
295
		return $this->type;
296
	}
297
298
	/**
299
	 * Getting column name.
300
	 *
301
	 * @return string columnName
302
	 */
303
	public function getColumnName()
304
	{
305
		return $this->has('columnname') ? $this->get('columnname') : $this->columnName;
306
	}
307
308
	/**
309
	 * Get label.
310
	 *
311
	 * @return string
312
	 */
313
	public function getLabel(): string
314
	{
315
		return $this->get('label');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->get('label') could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
316
	}
317
318
	/**
319
	 * Getting column name.
320
	 *
321
	 * @return array customColumn
322
	 */
323
	public function getCustomColumn()
324
	{
325
		$columns = [];
326
		$schame = \App\Db::getInstance()->getSchema();
327
		foreach ($this->customColumn as $name => $columnCriteria) {
328
			if (\is_array($columnCriteria)) {
329
				[$type, $length, $default, $unsigned] = array_pad($columnCriteria, 4, null);
330
				$columnCriteria = $schame->createColumnSchemaBuilder($type, $length);
331
				if (null !== $default) {
332
					$columnCriteria->defaultValue($default);
333
				}
334
				if (null !== $unsigned) {
335
					$columnCriteria->unsigned();
336
				}
337
			}
338
			$columns[$name] = $columnCriteria;
339
		}
340
341
		return $columns;
342
	}
343
344
	/**
345
	 * Check if the field is summed up.
346
	 *
347
	 * @return bool
348
	 */
349
	public function isSummary(): bool
350
	{
351
		return $this->summationValue;
352
	}
353
354
	/**
355
	 * Gets default value by field.
356
	 *
357
	 * @param string $columnName
358
	 *
359
	 * @return mixed
360
	 */
361
	public function getDefaultValue(string $columnName = '')
362
	{
363
		if (!$columnName || $columnName === $this->getColumnName()) {
364
			$value = $this->has('defaultvalue') ? $this->get('defaultvalue') : $this->defaultValue;
365
		} else {
366
			$value = $this->customDefault[$columnName] ?? '';
367
		}
368
369
		return $value;
370
	}
371
372
	/**
373
	 * Getting value to display.
374
	 *
375
	 * @param mixed $value
376
	 * @param array $rowData
377
	 * @param bool  $rawText
378
	 *
379
	 * @return string
380
	 */
381
	public function getDisplayValue($value, array $rowData = [], bool $rawText = false)
382
	{
383
		return $value ? \App\Purifier::encodeHtml($value) : '';
384
	}
385
386
	/**
387 2
	 * Function to get the list value in display view.
388
	 *
389 2
	 * @param mixed $value
390 2
	 * @param array $rowData
391 2
	 * @param bool  $rawText
392 2
	 *
393
	 * @return mixed
394
	 */
395 2
	public function getListViewDisplayValue($value, array $rowData = [], bool $rawText = false)
396
	{
397
		return $this->getDisplayValue($value, $rowData, $rawText);
398
	}
399
400
	/**
401
	 * Get value for Edit view.
402
	 *
403
	 * @param array  $itemData
404
	 * @param string $column
405
	 *
406
	 * @return string|int
407 1
	 */
408
	public function getEditValue(array $itemData, string $column = '')
409 1
	{
410 1
		if (!$column) {
411 1
			$column = $this->getColumnName();
412 1
		}
413 1
		$value = '';
414 1
		if (isset($itemData[$column])) {
415
			$value = $itemData[$column];
416 1
		} elseif (($default = \App\Config::module($this->getModuleName(), 'defaultInventoryData', [])[$column] ?? null) !== null) {
417
			$value = $default;
418
		} elseif ($column === $this->getColumnName()) {
419
			$value = $this->getDefaultValue();
420
		}
421
422
		return $value;
423
	}
424
425
	/**
426
	 * Function to check if the current field is mandatory or not.
427
	 *
428
	 * @return bool
429
	 */
430
	public function isMandatory()
431
	{
432 2
		return true;
433
	}
434 2
435
	/**
436
	 * Function to check whether the current field is visible.
437
	 *
438
	 * @return bool
439
	 */
440
	public function isVisible()
441
	{
442
		return self::FIELD_HIDDEN !== $this->get('displaytype');
443
	}
444
445
	/**
446
	 * Function to check if field is visible in detail view.
447 2
	 *
448
	 * @return bool
449 2
	 */
450
	public function isVisibleInDetail()
451
	{
452 2
		return \in_array($this->get('displaytype'), [self::FIELD_VISIBLE_EVERYWHERE, self::FIELD_READONLY, self::FIELD_VISIBLE_IN_DETAIL]);
453
	}
454
455 2
	/**
456
	 * Function to check whether the current field is editable.
457
	 *
458
	 * @return bool
459
	 */
460
	public function isEditable(): bool
461
	{
462
		return \in_array($this->get('displaytype'), [self::FIELD_VISIBLE_EVERYWHERE, self::FIELD_READONLY]);
463
	}
464
465
	/**
466
	 * Function checks if the field is read-only.
467
	 *
468
	 * @return bool
469
	 */
470
	public function isReadOnly()
471
	{
472
		return self::FIELD_READONLY === $this->get('displaytype');
473
	}
474
475
	/** {@inheritdoc} */
476
	public function set($key, $value, $register = false)
477
	{
478
		if ($this->getId() && !\in_array($key, ['id']) && (\array_key_exists($key, $this->value) && $this->value[$key] != $value)) {
479
			$this->changes[$key] = $this->get($key);
480
		}
481
		return parent::set($key, $value);
482
	}
483
484
	/**
485
	 * Sum the field value for each row.
486
	 *
487
	 * @param array    $data
488
	 * @param int|null $groupId
489
	 *
490
	 * @return int|float
491 2
	 */
492
	public function getSummaryValuesFromData($data, ?int $groupId = null)
493 2
	{
494 2
		$sum = 0;
495 2
		if (\is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) is always true.
Loading history...
496 2
			foreach ($data as $row) {
497 2
				if (null !== $groupId && $groupId !== $row['groupid'] ?? -1) {
498
					continue;
499 2
				}
500 2
				$sum += $row[$this->getColumnName()];
501 2
			}
502 2
		}
503 2
		return $sum;
504 2
	}
505 2
506
	/**
507
	 * Gets relation field.
508 2
	 *
509
	 * @param string $related
510
	 *
511
	 * @throws \App\Exceptions\AppException
512
	 *
513
	 * @return bool|\Vtiger_Field_Model
514
	 */
515 1
	public function getMapDetail(string $related)
516
	{
517 1
		$inventory = Vtiger_Inventory_Model::getInstance($this->getModuleName());
518
		$fields = $inventory->getAutoCompleteFields();
519
		$field = false;
520
		if ($mapDetail = $fields[$related][$this->getColumnName()] ?? false) {
521
			$moduleModel = Vtiger_Module_Model::getInstance($related);
522
			$field = Vtiger_Field_Model::getInstance($mapDetail['field'], $moduleModel);
523
		}
524
		return $field;
525
	}
526
527
	public function getFieldDataType()
528
	{
529
		return $this->fieldDataType;
530
	}
531
532
	/**
533
	 * Gets database value.
534
	 *
535
	 * @param mixed       $value
536
	 * @param string|null $name
537
	 *
538
	 * @return mixed
539
	 */
540
	public function getDBValue($value, ?string $name = '')
541
	{
542
		return $value;
543
	}
544
545
	/**
546
	 * Verification of data.
547
	 *
548
	 * @param mixed  $value
549
	 * @param string $columnName
550
	 * @param bool   $isUserFormat
551
	 * @param mixed  $originalValue
552
	 *
553
	 * @throws \App\Exceptions\Security
554
	 */
555
	public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null)
556
	{
557
		if (!is_numeric($value) && (\is_string($value) && $value !== strip_tags($value))) {
558
			throw new \App\Exceptions\Security('ERR_ILLEGAL_FIELD_VALUE||' . ($columnName ?? $this->getColumnName()) . '||' . $this->getModuleName() . '||' . $value, 406);
559
		}
560
		if (App\TextUtils::getTextLength($value) > $this->maximumLength) {
561
			throw new \App\Exceptions\Security('ERR_VALUE_IS_TOO_LONG||' . ($columnName ?? $this->getColumnName()) . '||' . $this->getModuleName() . '||' . $value, 406);
562
		}
563
	}
564
565
	/**
566
	 * Sets default data config.
567
	 *
568
	 * @return $this
569
	 */
570
	public function setDefaultDataConfig()
571
	{
572
		$this->set('columnname', $this->columnName)
573
			->set('label', $this->defaultLabel)
574
			->set('presence', 0)
575
			->set('defaultvalue', $this->defaultValue)
576
			->set('displaytype', $this->displayType)
577
			->set('invtype', $this->type)
578
			->set('block', current($this->blocks))
579
			->set('colspan', $this->colSpan);
580
581
		return $this;
582
	}
583
584
	/**
585
	 * Field required to make an entry.
586
	 *
587
	 * @return bool
588
	 */
589
	public function isRequired()
590
	{
591
		return false;
592
	}
593
594
	/**
595
	 * Sets value data.
596
	 *
597
	 * @param \Vtiger_Record_Model $recordModel
598
	 * @param array                $item
599
	 * @param bool                 $userFormat
600
	 *
601
	 * @throws \App\Exceptions\AppException
602
	 * @throws \App\Exceptions\Security
603
	 */
604
	public function setValueToRecord(Vtiger_Record_Model $recordModel, array $item, bool $userFormat)
605
	{
606
		$column = $this->getColumnName();
607
		$baseValue = $item[$column] ?? null;
608
		$value = $this->getValueForSave($item, $userFormat, $column);
609
		if ($userFormat && $baseValue) {
610
			$baseValue = $this->getDBValue($baseValue, $column);
611
		}
612
		$this->validate($value, $column, false, $baseValue);
613
614
		$itemId = $item['id'];
615
		$addToChanges = !$recordModel->isNew() && is_numeric($itemId) && !$this->compare($value, $recordModel->getInventoryData()[$itemId][$column] ?? '', $column);
616
		$recordModel->setInventoryItemPart($itemId, $column, $value, $addToChanges);
617
		if ($customColumn = $this->getCustomColumn()) {
618
			foreach (array_keys($customColumn) as $column) {
619
				$value = $this->getValueForSave($item, $userFormat, $column);
620
				$this->validate($value, $column, false);
621
				$addToChanges = !$recordModel->isNew() && is_numeric($itemId) && !$this->compare($value, $recordModel->getInventoryData()[$itemId][$column] ?? '', $column);
622
				$recordModel->setInventoryItemPart($itemId, $column, $value, $addToChanges);
623
			}
624
		}
625
	}
626
627
	/**
628
	 * Compare two values.
629
	 *
630
	 * @param mixed  $value
631
	 * @param mixed  $prevValue
632
	 * @param string $column
633
	 *
634
	 * @return bool
635
	 */
636
	public function compare($value, $prevValue, string $column): bool
637
	{
638
		return (string) $value === (string) $prevValue;
639
	}
640
641
	/**
642
	 * Gets purify type.
643
	 *
644
	 * @return array
645
	 */
646
	public function getPurifyType()
647
	{
648
		return [$this->getColumnName() => $this->purifyType] + $this->customPurifyType;
649
	}
650
651
	/**
652
	 * Get information about field.
653
	 *
654
	 * @return array
655
	 */
656
	public function getFieldInfo(): array
657
	{
658
		return [
659
			'maximumlength' => $this->maximumLength
660
		];
661
	}
662
663
	/**
664
	 * Get maximum length by column.
665
	 *
666
	 * @param string $columnName
667
	 *
668
	 * @return int|string
669
	 */
670
	public function getMaximumLengthByColumn(string $columnName)
671
	{
672
		if ($columnName === $this->getColumnName()) {
673
			$value = $this->maximumLength;
674
		} else {
675
			$value = $this->customMaximumLength[$columnName] ?? '';
676
		}
677
678
		return $value;
679
	}
680
681
	/**
682
	 * Get pervious value by field.
683
	 *
684
	 * @param string $fieldName
685
	 *
686
	 * @return mixed
687
	 */
688
	public function getPreviousValue(string $fieldName = '')
689
	{
690
		return $fieldName ? ($this->changes[$fieldName] ?? null) : $this->changes;
691
	}
692
693
	/**
694
	 * Check if the field is synchronized.
695
	 *
696
	 * @return bool
697
	 */
698
	public function isSync(): bool
699
	{
700
		return $this->sync;
701
	}
702
703
	/**
704
	 * Gets config fields data.
705
	 *
706
	 * @return array
707
	 */
708
	public function getConfigFieldsData(): array
709
	{
710
		$row = [
711
			'invtype' => [
712
				'name' => 'invtype',
713
				'column' => 'invtype',
714
				'uitype' => 1,
715
				'label' => 'LBL_NAME_FIELD',
716
				'maximumlength' => '30',
717
				'typeofdata' => 'V~M',
718
				'purifyType' => \App\Purifier::STANDARD,
719
				'isEditableReadOnly' => true,
720
			],
721
			'label' => [
722
				'name' => 'label',
723
				'label' => 'LBL_LABEL_NAME',
724
				'uitype' => 1,
725
				'maximumlength' => '50',
726
				'typeofdata' => 'V~M',
727
				'purifyType' => \App\Purifier::TEXT,
728
			],
729
			'displaytype' => [
730
				'name' => 'displaytype',
731
				'label' => 'LBL_DISPLAY_TYPE',
732
				'uitype' => 16,
733
				'maximumlength' => '127',
734
				'typeofdata' => 'V~M',
735
				'purifyType' => \App\Purifier::INTEGER,
736
				'picklistValues' => [],
737
			],
738
			'colspan' => [
739
				'name' => 'colspan',
740
				'label' => 'LBL_COLSPAN',
741
				'uitype' => 7,
742
				'maximumlength' => '0,100',
743
				'typeofdata' => 'N~M',
744
				'purifyType' => \App\Purifier::INTEGER,
745
				'tooltip' => 'LBL_MAX_WIDTH_COLUMN_INFO'
746
			]
747
		];
748
749
		$qualifiedModuleName = 'Settings:LayoutEditor';
750
		foreach ($this->displayTypeBase() as $key => $value) {
751
			$row['displaytype']['picklistValues'][$key] = \App\Language::translate($value, $qualifiedModuleName);
752
		}
753
754
		return $row;
755
	}
756
757
	/**
758
	 * Gets config fields.
759
	 *
760
	 * @return Vtiger_Field_Model[]
761
	 */
762
	public function getConfigFields(): array
763
	{
764
		$module = 'LayoutEditor';
765
		$fields = [];
766
		foreach ($this->getConfigFieldsData() as $name => $data) {
767
			$fieldModel = \Vtiger_Field_Model::init($module, $data, $name);
768
			if (null !== $this->get($name)) {
769
				$fieldModel->set('fieldvalue', $this->get($name));
770
			} elseif (isset($this->getParamsConfig()[$name])) {
771
				$fieldModel->set('fieldvalue', $this->getParamsConfig()[$name]);
772
			} elseif (property_exists($this, $name) && null !== $this->{$name} && '' !== $this->{$name}) {
773
				$fieldModel->set('fieldvalue', $this->{$name});
774
			} elseif (($default = $fieldModel->get('defaultvalue')) !== null) {
775
				$fieldModel->set('fieldvalue', $default);
776
			}
777
			$fields[$name] = $fieldModel;
778
		}
779
780
		return $fields;
781
	}
782
783
	/**
784
	 * Gets config field.
785
	 *
786
	 * @param string $key
787
	 *
788
	 * @return Vtiger_Field_Model|null
789
	 */
790
	public function getConfigField(string $key): ?Vtiger_Field_Model
791
	{
792
		return $this->getConfigFields()[$key] ?? null;
793
	}
794
}
795