Settings_LayoutEditor_Field_Model::getFieldInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 9
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/* +**********************************************************************************
3
 * The contents of this file are subject to the vtiger CRM Public License Version 1.1
4
 * ("License"); You may not use this file except in compliance with the License
5
 * The Original Code is:  vtiger CRM Open Source
6
 * The Initial Developer of the Original Code is vtiger.
7
 * Portions created by vtiger are Copyright (C) vtiger.
8
 * All Rights Reserved.
9
 * Contributor(s): YetiForce S.A.
10
 * ********************************************************************************** */
11
12
class Settings_LayoutEditor_Field_Model extends Settings_Vtiger_Field_Model
13
{
14
	/** @var Settings_Vtiger_Field_Model[] Item field models */
15
	private $items = [];
16
	/** @var Vtiger_Field_Model|null Source field model */
17 21
	public $sourceFieldModel;
18
	/** @var array Webservice app visibility */
19 21
	const WEBSERVICE_APPS_VISIBILITY = [
20 21
		0 => 'LBL_WSA_VISIBILITY_DEFAULT',
21
		1 => 'LBL_DISPLAY_TYPE_1',
22 21
		2 => 'LBL_DISPLAY_TYPE_2',
23 21
		3 => 'LBL_DISPLAY_TYPE_3',
24 21
		4 => 'LBL_DISPLAY_TYPE_4',
25 21
		9 => 'LBL_DISPLAY_TYPE_9',
26 21
		10 => 'LBL_DISPLAY_TYPE_10',
27 21
		6 => 'LBL_DISPLAY_TYPE_6',
28 21
	];
29 21
30
	/** @var array Translations of field types */
31 21
	public $fieldTypeLabel = [
32
		'string' => 'Text',
33 21
		'date' => 'Date',
34 21
		'integer' => 'Integer',
35
		'double' => 'Decimal',
36 21
		'percentage' => 'Percent',
37
		'phone' => 'Phone',
38 21
		'email' => 'Email',
39
		'time' => 'Time',
40
		'picklist' => 'Picklist',
41
		'url' => 'URL',
42
		'multipicklistTags' => 'MultipicklistTags',
43
		'text' => 'TextArea',
44 21
		'languages' => 'LBL_LANGUAGE',
45 3
		'multipicklist' => 'MultiSelectCombo',
46 3
		'country' => 'Country',
47 3
		'reference' => 'Related1M',
48 3
		'userCreator' => 'LBL_USER',
49 3
		'boolean' => 'Checkbox',
50 3
		'image' => 'Image',
51
		'datetime' => 'DateTime',
52 3
		'currency' => 'Currency',
53
		'skype' => 'Skype',
54
		'tree' => 'Tree',
55 3
		'multiReferenceValue' => 'MultiReferenceValue',
56
		'multiReference' => 'MultiReference',
57 3
		'rangeTime' => 'RangeTime',
58
		'categoryMultipicklist' => 'CategoryMultipicklist',
59
		'multiImage' => 'MultiImage',
60
		'twitter' => 'Twitter',
61 21
		'multiEmail' => 'MultiEmail',
62 1
		'smtp' => 'Smtp',
63 1
		'serverAccess' => 'ServerAccess',
64 1
		'multiDomain' => 'MultiDomain',
65 1
		'token' => 'Token',
66 1
		'multiAttachment' => 'MultiAttachment',
67
		'mapCoordinates' => 'MapCoordinates',
68 21
		'advPercentage' => 'AdvPercentage',
69 21
		'group' => 'Group'
70 21
	];
71 21
72 21
	/** @var array Webservice field data */
73 21
	protected $webserviceData;
74
75
	/**
76
	 * Get field data type label.
77
	 *
78
	 * @return string
79 21
	 */
80
	public function getFieldDataTypeLabel(): string
81
	{
82
		if (300 === $this->getUIType()) {
83
			$label = 'Editor';
84
		} else {
85
			$label = $this->fieldTypeLabel[$this->getFieldDataType()] ?? '';
86
		}
87
		return $label;
88
	}
89
90
	/**
91
	 * Function to remove field.
92
	 */
93
	public function delete()
94
	{
95
		$db = \App\Db::getInstance();
96
		try {
97
			parent::delete();
98
99
			$fldModule = $this->getModuleName();
100
			$id = $this->getId();
101
			$fieldname = $this->getName();
102
			$tablename = $this->get('table');
103
			$columnName = $this->get('column');
104
			$tabId = $this->getModuleId();
105
			if ('vtiger_crmentity' !== $tablename) {
106
				$db->createCommand()->dropColumn($tablename, $columnName)->execute();
107
			}
108
			App\Db::getInstance('admin')->createCommand()->delete('a_#__mapped_fields', ['or', ['source' => (string) $id], ['target' => (string) $id]])->execute();
109
			//we have to remove the entries in customview and report related tables which have this field ($colName)
110
			$db->createCommand()->delete('vtiger_cvcolumnlist', ['field_name' => $fieldname, 'module_name' => $fldModule])->execute();
111
			$db->createCommand()->delete('vtiger_cvcolumnlist', [
112
				'source_field_name' => $fieldname,
113
				'cvid' => (new \App\Db\Query())->select(['cvid'])->from('vtiger_customview')->where(['entitytype' => $fldModule]),
114
			])->execute();
115
			$db->createCommand()->delete('u_#__cv_condition', ['field_name' => $fieldname, 'module_name' => $fldModule])->execute();
116
			//Deleting from convert lead mapping vtiger_table- Jaguar
117
			if ('Leads' === $fldModule) {
118
				$db->createCommand()->delete('vtiger_convertleadmapping', ['leadfid' => $id])->execute();
119
			} elseif ('Accounts' === $fldModule) {
120
				$mapDelId = ['Accounts' => 'accountfid'];
121
				$db->createCommand()->update('vtiger_convertleadmapping', [$mapDelId[$fldModule] => 0], [$mapDelId[$fldModule] => $id])->execute();
122
			}
123
			switch ($this->getFieldDataType()) {
124
				case 'picklist':
125
				case 'multipicklist':
126
						$query = (new \App\Db\Query())->from('vtiger_field')
127
							->where(['fieldname' => $fieldname])
128
							->andWhere(['in', 'uitype', [15, 16, 33]]);
129
						$dataReader = $query->createCommand()->query();
130
						if (!$dataReader->count()) {
131
							$db->createCommand()->dropTable('vtiger_' . $fieldname)->execute();
132
							//To Delete Sequence Table
133
							if ($db->isTableExists('vtiger_' . $fieldname . '_seq')) {
134
								$db->createCommand()->dropTable('vtiger_' . $fieldname . '_seq')->execute();
135
							}
136
							$db->createCommand()->delete('vtiger_picklist', ['name' => $fieldname])->execute();
137
						}
138
					break;
139
					case 'mapCoordinates':
140
						\App\Fields\MapCoordinates::reloadHandler();
0 ignored issues
show
Bug introduced by
The type App\Fields\MapCoordinates was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
141
						break;
142
				default:
143
					break;
144
			}
145
			$entityInfo = \App\Module::getEntityInfo($fldModule);
146
			$searchModel = Settings_Search_Module_Model::getInstance('Settings:Search');
147
			foreach (['fieldnameArr' => 'fieldname', 'searchcolumnArr' => 'searchcolumn'] as $key => $name) {
148
				if (false !== ($fieldNameKey = array_search($fieldname, $entityInfo[$key]))) {
149
					unset($entityInfo[$key][$fieldNameKey]);
150
					$params = [
151
						'name' => $name,
152
						'tabid' => $tabId,
153
						'value' => $entityInfo[$key],
154
					];
155
					$searchModel->save($params);
156
				}
157
			}
158
		} catch (\Throwable $ex) {
159
			\App\Log::error($ex->__toString());
160
			throw $ex;
161
		}
162
	}
163
164
	/**
165
	 * Function to Move the field.
166
	 *
167
	 * @param <Array> $fieldNewDetails
0 ignored issues
show
Documentation Bug introduced by
The doc comment <Array> at position 0 could not be parsed: Unknown type name '<' at position 0 in <Array>.
Loading history...
168
	 * @param <Array> $fieldOlderDetails
169
	 */
170
	public function move($fieldNewDetails, $fieldOlderDetails)
171
	{
172
		$db = \App\Db::getInstance();
173
		$newBlockId = $fieldNewDetails['blockId'];
174
		$olderBlockId = $fieldOlderDetails['blockId'];
175
176
		$newSequence = $fieldNewDetails['sequence'];
177
		$olderSequence = $fieldOlderDetails['sequence'];
178
179
		if ($olderBlockId == $newBlockId) {
180
			if ($newSequence > $olderSequence) {
181
				$db->createCommand()->update('vtiger_field', ['sequence' => new \yii\db\Expression('sequence - 1')], ['and', 'sequence > :olderSequence', 'sequence <= :newSequence', 'block = :olderBlockId'], [':olderSequence' => $olderSequence, ':newSequence' => $newSequence, ':olderBlockId' => $olderBlockId])->execute();
182
			} elseif ($newSequence < $olderSequence) {
183
				$db->createCommand()->update('vtiger_field', ['sequence' => new \yii\db\Expression('sequence + 1')], ['and', 'sequence < :olderSequence', 'sequence >= :newSequence', 'block = :olderBlockId'], [':olderSequence' => $olderSequence, ':newSequence' => $newSequence, ':olderBlockId' => $olderBlockId])->execute();
184
			}
185
			$db->createCommand()->update('vtiger_field', ['sequence' => $newSequence], ['fieldid' => $this->getId()])->execute();
186
		} else {
187
			$db->createCommand()->update('vtiger_field', ['sequence' => new \yii\db\Expression('sequence - 1')], ['and', 'sequence > :olderSequence', 'block = :olderBlockId'], [':olderSequence' => $olderSequence, ':olderBlockId' => $olderBlockId])->execute();
188
			$db->createCommand()->update('vtiger_field', ['sequence' => new \yii\db\Expression('sequence - 1')], ['and', 'sequence >= :newSequence', 'block = :newBlockId'], [':newSequence' => $newSequence, ':newBlockId' => $newBlockId])->execute();
189
190
			$db->createCommand()->update('vtiger_field', ['sequence' => $newSequence, 'block' => $newBlockId], ['fieldid' => $this->getId()])->execute();
191
		}
192
	}
193
194
	/**
195
	 * Function to activate field.
196
	 *
197
	 * @param int[] $fieldIdsList
198
	 * @param int   $blockId
199
	 */
200
	public static function makeFieldActive($fieldIdsList, $blockId)
201
	{
202
		$maxSequence = (new \App\Db\Query())->from('vtiger_field')
203
			->where(['block' => $blockId, 'presence' => [0, 2]])->max('sequence');
204
		foreach ($fieldIdsList as $fieldId) {
205
			++$maxSequence;
206
			$fieldInstance = self::getInstance($fieldId);
207
			$fieldInstance->set('sequence', $maxSequence);
208
			$fieldInstance->set('presence', 2);
209
			$fieldInstance->save();
210
		}
211
	}
212
213
	/**
214
	 * Set source field model.
215
	 *
216
	 * @param Vtiger_Field_Model $fieldModel
217
	 *
218
	 * @return $this
219
	 */
220
	public function setSourceField(Vtiger_Field_Model $fieldModel)
221
	{
222
		$this->sourceFieldModel = $fieldModel;
223
224
		return $this;
225
	}
226
227
	/**
228
	 * Get source field model.
229
	 *
230
	 * @return Vtiger_Field_Model|null
231
	 */
232
	public function getSourceField(): ?Vtiger_Field_Model
233
	{
234 21
		return $this->sourceFieldModel;
235
	}
236 21
237 21
	/**
238 21
	 * Get module model.
239 21
	 *
240 21
	 * @return Vtiger_Module_Model
241
	 */
242 21
	public function getModule()
243
	{
244
		return $this->getSourceField() ? $this->getSourceField()->getModule() : parent::getModule();
245
	}
246
247
	/**
248
	 * Function which specifies whether the field can have mandatory switch to happen.
249
	 *
250
	 * @return bool - true if we can make a field mandatory and non mandatory , false if we cant change previous state
251
	 */
252
	public function isMandatoryOptionDisabled(): bool
253
	{
254
		$compulsoryMandatoryFieldList = [];
255
		if (!$this->getSourceField()) {
256
			$compulsoryMandatoryFieldList = $this->getModule()->getEntityInstance()->mandatory_fields ?? [];
257
		}
258
259
		return \in_array($this->getName(), $compulsoryMandatoryFieldList) || \in_array($this->get('uitype'), ['4', '70']);
260
	}
261
262
	/**
263
	 * Function which will specify whether the active option is disabled.
264
	 *
265
	 * @return bool
266
	 */
267
	public function isActiveOptionDisabled(): bool
268
	{
269
		if (!($sourceField = $this->getSourceField())) {
270
			$sourceField = $this;
271
		}
272
273
		return 0 === (int) $sourceField->get('presence') || 306 === (int) $sourceField->get('uitype') || $this->isMandatoryOptionDisabled();
274
	}
275
276
	/**
277
	 * Function which will specify whether the quickcreate option is disabled.
278
	 *
279
	 * @return bool
280
	 */
281
	public function isQuickCreateOptionDisabled()
282
	{
283
		$moduleModel = $this->getModule();
284
		if (0 == $this->get('quickcreate') || 3 == $this->get('quickcreate') || !$moduleModel->isQuickCreateSupported()) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->get('quickcreate') of type mixed|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
285
			return true;
286
		}
287
		return false;
288
	}
289
290
	/**
291
	 * Function which will specify whether the mass edit option is disabled.
292
	 *
293
	 * @return bool
294
	 */
295
	public function isMassEditOptionDisabled()
296
	{
297
		if (0 == $this->get('masseditable') || 1 != $this->get('displaytype') || 3 == $this->get('masseditable')) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $this->get('masseditable') of type mixed|null to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
298
			return true;
299
		}
300
		return false;
301
	}
302
303
	/**
304
	 * Function which will specify whether the default value option is disabled.
305
	 *
306
	 * @return bool
307
	 */
308
	public function isDefaultValueOptionDisabled(): bool
309
	{
310
		if ($this->isMandatoryOptionDisabled() || $this->isReferenceField() || 'image' === $this->getFieldDataType() || 'multiImage' === $this->getFieldDataType()) {
311
			return true;
312
		}
313
		return false;
314
	}
315
316
	/**
317
	 * A function that will determine if the default value option is disabled for an WebserviceApps configuration.
318
	 *
319
	 * @return bool
320
	 */
321
	public function isDefaultValueForWebservice(): bool
322
	{
323
		return !(\in_array($this->get('uitype'), ['4', '70']) || 'image' === $this->getFieldDataType() || 'multiImage' === $this->getFieldDataType());
324
	}
325
326
	/**
327
	 * Function to check whether summary field option is disable or not.
328
	 *
329
	 * @return bool true/false
330
	 */
331
	public function isSummaryFieldOptionDisabled()
332
	{
333
		return 70 === $this->get('uitype');
334
	}
335
336
	/**
337
	 * Function to check field is editable or not.
338
	 *
339
	 * @param string $viewName
340
	 *
341
	 * @return bool true/false
342
	 */
343
	public function isEditable(string $viewName = 'Edit'): bool
344
	{
345
		if ('ModComments' === $this->getModuleName() && \in_array($this->getName(), ['commentcontent', 'userid', 'created_user_id', 'customer', 'reasontoedit', 'parents', 'assigned_user_id', 'creator', 'modifiedtime', 'related_to', 'createdtime', 'parent_comments'])) {
346
			return false;
347
		}
348
		return true;
349
	}
350
351
	/**
352
	 * Function to get instance.
353
	 *
354
	 * @param string $value  - fieldname or fieldid
355
	 * @param <type> $module - optional - module instance
0 ignored issues
show
Documentation Bug introduced by
The doc comment <type> at position 0 could not be parsed: Unknown type name '<' at position 0 in <type>.
Loading history...
356
	 *
357
	 * @return self
358
	 */
359
	public static function getInstance($value, $module = false)
360
	{
361
		$fieldObject = parent::getInstance($value, $module);
362
		$objectProperties = get_object_vars($fieldObject);
363
		$fieldModel = new self();
364
		foreach ($objectProperties as $properName => $propertyValue) {
365
			$fieldModel->{$properName} = $propertyValue;
366
		}
367
		return $fieldModel;
368
	}
369
370
	/**
371
	 * Function to get all fields list for all blocks.
372
	 *
373
	 * @param array List of block ids
374
	 * @param Vtiger_Module_Model $moduleInstance
375
	 * @param mixed               $blockId
376
	 *
377
	 * @return array List of Field models Settings_LayoutEditor_Field_Model
378
	 */
379
	public static function getInstanceFromBlockIdList($blockId, $moduleInstance = false)
380
	{
381
		if (!\is_array($blockId)) {
382
			$blockId = [$blockId];
383
		}
384
		$query = (new \App\Db\Query())->from('vtiger_field')->where(['block' => $blockId])->orderBy('sequence');
385
		$dataReader = $query->createCommand()->query();
386
		$fieldModelsList = [];
387
		while ($row = $dataReader->read()) {
388
			$fieldModel = new self();
389
			$fieldModel->initialize($row);
390
			if ($moduleInstance) {
391
				$fieldModel->setModule($moduleInstance);
392
			}
393
			$fieldModelsList[$row['fieldname']] = $fieldModel;
394
		}
395
		$dataReader->close();
396
397
		return $fieldModelsList;
398
	}
399
400
	/** {@inheritdoc} */
401
	public function getFieldInfo(): array
402
	{
403
		$fieldInfo = parent::getFieldInfo();
404
		$fieldInfo['isQuickCreateDisabled'] = $this->isQuickCreateOptionDisabled();
405
		$fieldInfo['isSummaryField'] = $this->isSummaryField();
406
		$fieldInfo['isSummaryFieldDisabled'] = $this->isSummaryFieldOptionDisabled();
407
		$fieldInfo['isMassEditDisabled'] = $this->isMassEditOptionDisabled();
408
		$fieldInfo['isDefaultValueDisabled'] = $this->isDefaultValueOptionDisabled();
409
		return $fieldInfo;
410
	}
411
412
	/**
413
	 * Get webservice data.
414
	 *
415
	 * @param int $webserviceApp
416
	 *
417
	 * @return array
418
	 */
419
	public function getWebserviceData(int $webserviceApp): array
420
	{
421
		if (isset($this->webserviceData)) {
422
			return $this->webserviceData;
423
		}
424
		return $this->webserviceData = (new \App\Db\Query())->from('w_#__fields_server')->where(['fieldid' => $this->getId(), 'serverid' => $webserviceApp])->one(\App\Db::getInstance('webservice')) ?: [];
425
	}
426
427
	/**
428
	 * Load webservice data.
429
	 *
430
	 * @param int $webserviceApp
431
	 *
432
	 * @return void
433
	 */
434
	public function loadWebserviceData(int $webserviceApp): void
435
	{
436
		$data = $this->getWebserviceData($webserviceApp);
437
		if (empty($data['is_default'])) {
438
			$this->set('defaultvalue', '');
439
		} else {
440
			$this->set('defaultvalue', $data['default_value']);
441
		}
442
		if (!empty($data['visibility'])) {
443
			$this->set('displaytype', $data['visibility']);
444
		}
445
	}
446
447
	/**
448
	 * Update webservice data.
449
	 *
450
	 * @param array $data
451
	 * @param int   $webserviceApp
452
	 *
453
	 * @return void
454
	 */
455
	public function updateWebserviceData(array $data, int $webserviceApp): void
456
	{
457
		$createCommand = \App\Db::getInstance('webservice')->createCommand();
458
		if ($this->getWebserviceData($webserviceApp)) {
459
			$createCommand->update('w_#__fields_server', $data, ['fieldid' => $this->getId(), 'serverid' => $webserviceApp])->execute();
460
		} else {
461
			$createCommand->insert('w_#__fields_server', \App\Utils::merge($data, ['fieldid' => $this->getId(), 'serverid' => $webserviceApp]))->execute();
462
		}
463
		\App\Cache::delete('WebserviceAppsFields', $webserviceApp);
464
	}
465
466
	/**
467
	 * Get fields instance by name.
468
	 *
469
	 * @param string $name
470
	 *
471
	 * @return Vtiger_Field_Model
472
	 */
473
	public function getFieldItemByName($name)
474
	{
475
		if (isset($this->items[$name])) {
476
			return $this->items[$name];
477
		}
478
		$params = [];
479
		$itemModel = null;
480
		$qualifiedModuleName = 'Settings:LayoutEditor';
481
		switch ($name) {
482
			case 'icon':
483
				$params = [
484
					'name' => $name,
485
					'column' => $name,
486
					'label' => 'LBL_ICON',
487
					'uitype' => 62,
488
					'typeofdata' => 'V~O',
489
					'maximumlength' => '255',
490
					'purifyType' => \App\Purifier::TEXT,
491
					'table' => 'vtiger_field',
492
					'fieldDataType' => 'icon'
493
				];
494
				break;
495
			case 'fieldlabel':
496
				$params = [
497
					'name' => $name,
498
					'column' => $name,
499
					'label' => 'LBL_LABEL',
500
					'uitype' => 1,
501
					'typeofdata' => 'V~M',
502
					'maximumlength' => '50',
503
					'purifyType' => \App\Purifier::TEXT
504
				];
505
				break;
506
			case 'mandatory':
507
				$params = [
508
					'name' => $name,
509
					'column' => $name,
510
					'label' => 'LBL_MANDATORY_FIELD',
511
					'uitype' => 56,
512
					'typeofdata' => 'C~O',
513
					'maximumlength' => '1',
514
					'purifyType' => \App\Purifier::BOOL
515
				];
516
				break;
517
			case 'presence':
518
				$params = [
519
					'name' => $name,
520
					'column' => $name,
521
					'label' => 'LBL_ACTIVE',
522
					'uitype' => 56,
523
					'typeofdata' => 'C~O',
524
					'maximumlength' => '1',
525
					'purifyType' => \App\Purifier::BOOL
526
				];
527
				break;
528
			case 'quickcreate':
529
				$params = [
530
					'name' => $name,
531
					'column' => $name,
532
					'label' => 'LBL_QUICK_CREATE',
533
					'uitype' => 56,
534
					'typeofdata' => 'C~O',
535
					'maximumlength' => '1',
536
					'purifyType' => \App\Purifier::BOOL
537
				];
538
				break;
539
			case 'summaryfield':
540
				$params = [
541
					'name' => $name,
542
					'column' => $name,
543
					'label' => 'LBL_SUMMARY_FIELD',
544
					'uitype' => 56,
545
					'typeofdata' => 'C~O',
546
					'maximumlength' => '1',
547
					'purifyType' => \App\Purifier::BOOL
548
				];
549
				break;
550
			case 'header_field':
551
				$params = [
552
					'name' => $name,
553
					'column' => $name,
554
					'label' => 'LBL_HEADER_FIELD',
555
					'uitype' => 56,
556
					'typeofdata' => 'C~O',
557
					'maximumlength' => '1',
558
					'purifyType' => \App\Purifier::BOOL
559
				];
560
				break;
561
			case 'masseditable':
562
				$params = [
563
					'name' => $name,
564
					'column' => $name,
565
					'label' => 'LBL_MASS_EDIT',
566
					'uitype' => 56,
567
					'typeofdata' => 'C~O',
568
					'maximumlength' => '1',
569
					'purifyType' => \App\Purifier::BOOL
570
				];
571
				break;
572
			case 'generatedtype':
573
				$params = [
574
					'name' => $name,
575
					'column' => $name,
576
					'label' => 'LBL_GENERATED_TYPE',
577
					'uitype' => 56,
578
					'typeofdata' => 'C~O',
579
					'maximumlength' => '1',
580
					'purifyType' => \App\Purifier::BOOL,
581
					'isEditableReadOnly' => !App\Config::developer('CHANGE_GENERATEDTYPE')
582
				];
583
				break;
584
			case 'defaultvalue':
585
				$params = [
586
					'name' => $name,
587
					'column' => $name,
588
					'label' => 'LBL_DEFAULT_VALUE',
589
					'uitype' => 56,
590
					'typeofdata' => 'C~O',
591
					'maximumlength' => '1',
592
					'purifyType' => \App\Purifier::BOOL
593
				];
594
				break;
595
			case 'fieldMask':
596
				$params = [
597
					'name' => $name,
598
					'column' => $name,
599
					'label' => 'LBL_FIELD_MASK',
600
					'uitype' => 1,
601
					'typeofdata' => 'V~O',
602
					'maximumlength' => '25',
603
					'purifyType' => \App\Purifier::TEXT,
604
					'tooltip' => 'LBL_FIELD_MASK_INFO'
605
				];
606
				break;
607
			default:
608
				break;
609
		}
610
		if ($params) {
611
			$itemModel = \Vtiger_Field_Model::init($qualifiedModuleName, $params, $name)->setSourceField($this);
0 ignored issues
show
Bug introduced by
The method setSourceField() does not exist on Vtiger_Field_Model. It seems like you code against a sub-type of Vtiger_Field_Model such as Settings_LayoutEditor_Field_Model. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

611
			$itemModel = \Vtiger_Field_Model::init($qualifiedModuleName, $params, $name)->/** @scrutinizer ignore-call */ setSourceField($this);
Loading history...
612
			if (null !== $this->get($name)) {
613
				$itemModel->set('fieldvalue', $this->get($name));
614
			} elseif (($defaultValue = $itemModel->get('defaultvalue')) !== null) {
615
				$itemModel->set('fieldvalue', $defaultValue);
616
			}
617
		}
618
619
		return $itemModel;
620
	}
621
}
622