1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Icon.php
См. документацию.
1<?php
2declare(strict_types=1);
3
5
8
9class Icon extends Node
10{
11 protected const TYPE = NodeType::Icon;
12 protected const DEFAULT_VENDOR = 'fas';
13 protected const DEFAULT_CLASS = 'fa-stars';
14 protected const ALLOWED_VENDORS = ['fat', 'fal', 'far', 'fas', 'fab'];
15
16 private ?array $classLists = null;
17 private ?array $originalClassLists = null;
18
19 public function __construct(string $code, array $data)
20 {
21 parent::__construct($code, $data);
22 foreach ($data['values'] as $classList)
23 {
24 $classListArray = [];
25 if (is_string($classList))
26 {
27 $classListArray = explode(' ', $classList);
28 }
29 if (is_array($classList))
30 {
31 $classListArray = $classList;
32 }
33 $this->originalClassLists[] = implode(' ', $classListArray);
34 $classListArray = array_filter($classListArray, static function($value) {
35 return $value !== null && str_starts_with($value, 'fa');
36 });
37 $classListArrayValues = array_values($classListArray);
38 $this->classLists[] = $classListArrayValues;
39 }
40 }
41
42 public function setData(array $data): void
43 {
44 $this->setClassLists($data);
45 }
46
47 public function getValues(?int $position = null): array
48 {
49 $nodeDataArray = [];
50
51 $codeSuffix = substr($this->getCode(), 1);
52
53 foreach ($this->classLists as $index => $classList)
54 {
55 $processedClassList = is_array($classList) ? implode(' ', $classList) : $classList;
56 $processedClassList = $codeSuffix . ' ' . $processedClassList;
57
58 $nodeDataArray[$index]['classList'] = $processedClassList;
59
60 if (isset($this->originalClassLists[$index]))
61 {
62 $classListOriginal = $this->originalClassLists[$index];
63 $classListOriginalArray = is_string($classListOriginal)
64 ? explode(' ', $classListOriginal)
65 : $classListOriginal;
66
67 $filteredClasses = array_filter($classListOriginalArray, static function($class) use ($codeSuffix) {
68 return $class !== $codeSuffix && (!str_starts_with($class, 'fa') || $class === 'fa');
69 });
70
71 if (!empty($filteredClasses))
72 {
73 $nodeDataArray[$index]['classList'] .= ' ' . implode(' ', $filteredClasses);
74 }
75 }
76 }
77
78 return $nodeDataArray;
79 }
80
81 protected function setClassLists(array $classLists): self
82 {
83 $this->classLists = $this->validateClassLists($classLists);
84
85 return $this;
86 }
87
88 protected function validateClassLists(array $classLists): array
89 {
90 $validatedClassLists = [];
91 foreach ($classLists as $classList)
92 {
93 $validatedClassLists[] = $this->validateClassList($classList);
94 }
95
96 return $validatedClassLists;
97 }
98
106 protected function validateClassList(string $classList): string
107 {
108 $classListArray = explode(' ', trim($classList));
109
110 if (count($classListArray) !== 2)
111 {
112 return implode(' ', [self::DEFAULT_VENDOR, self::DEFAULT_CLASS]);
113 }
114
115 $vendorName = $classListArray[0];
116
117 if (!in_array($vendorName, self::ALLOWED_VENDORS, true))
118 {
119 $vendorName = self::DEFAULT_VENDOR;
120 }
121
122 $className = $classListArray[1];
123
124 if (!str_starts_with($className, 'fa-'))
125 {
126 $className = self::DEFAULT_CLASS;
127 }
128
129 $iconContent = PreProcessing\Icon::getIconContentByClass($className, $vendorName);
130 if ($iconContent === null)
131 {
132 $iconContentFound = false;
133 foreach (self::ALLOWED_VENDORS as $vendor)
134 {
136 $className,
137 $vendor
138 );
139 if ($iconContent !== null)
140 {
141 $vendorName = $vendor;
142 $iconContentFound = true;
143 break;
144 }
145 }
146 if ($iconContentFound === false)
147 {
148 $vendorName = self::DEFAULT_VENDOR;
149 $className = self::DEFAULT_CLASS;
150 }
151 }
152
153 return implode(' ', [$vendorName, $className]);
154 }
155}
static getIconContentByClass(string $className, string $vendorName)
Определения icon.php:374
validateClassLists(array $classLists)
Определения Icon.php:88
__construct(string $code, array $data)
Определения Icon.php:19
const ALLOWED_VENDORS
Определения Icon.php:14
const DEFAULT_VENDOR
Определения Icon.php:12
validateClassList(string $classList)
Определения Icon.php:106
const DEFAULT_CLASS
Определения Icon.php:13
setClassLists(array $classLists)
Определения Icon.php:81
setData(array $data)
Определения Icon.php:42
getValues(?int $position=null)
Определения Icon.php:47
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936