Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
columnfactory.php
1<?php
2
4
8
10{
11 private ConfigFactory $editableConfigFactory;
12
13 public function __construct()
14 {
15 $this->editableConfigFactory = new ConfigFactory;
16 }
17
18 public function createFromArray(array $params): ?Column
19 {
20 if (!isset($params['id']))
21 {
22 return null;
23 }
24
25 $id = $params['id'];
26
27 $editable = $params['editable'] ?? null;
28 if (is_array($editable))
29 {
30 $editable['NAME'] ??= $id;
31 $editable['TYPE'] ??= Type::getEditorType(
32 (string)($params['type'] ?? '')
33 );
34 $params['editable'] = $this->editableConfigFactory->createFromArray($editable) ?? false;
35 }
36
37 if (isset($params['width']))
38 {
39 if (is_string($params['width']))
40 {
41 $re = '/^(\d+)px/';
42 if (preg_match($re, $params['width'], $m))
43 {
44 $params['width'] = (int)$m[1];
45 }
46 elseif (is_numeric($params['width']))
47 {
48 $params['width'] = (int)$params['width'];
49 }
50 else
51 {
52 $params['width'] = null;
53 }
54 }
55 }
56
57 // empty string and `false` convert to `null`
58 if (isset($params['sort']) && empty($params['sort']))
59 {
60 $params['sort'] = null;
61 }
62
63 return new Column($id, $params);
64 }
65}