10 static private $loaded =
false;
11 static private $entities = [];
12 static private $providers = [];
13 static private $filters = [];
14 static private $extensions = [];
20 return self::$extensions;
32 $entityId = $entity->
getId();
37 if (!is_string($entityId) || !isset(self::$entities[$entityId]))
42 if (array_key_exists($entityId, self::$providers))
44 return self::$providers[$entityId];
49 is_string($substituteEntityId)
50 && isset(self::$entities[$substituteEntityId][
'substitutes'])
51 && self::$entities[$substituteEntityId][
'substitutes'] === $entityId
54 $moduleId = self::$entities[$substituteEntityId][
'provider'][
'moduleId'] ??
null;;
55 $className = self::$entities[$substituteEntityId][
'provider'][
'className'] ??
null;
59 $moduleId = self::$entities[$entityId][
'provider'][
'moduleId'] ??
null;;
60 $className = self::$entities[$entityId][
'provider'][
'className'] ??
null;
63 self::$providers[$entityId] = self::createProvider($moduleId, $className, $options);
65 return self::$providers[$entityId];
73 public static function getFilters(
string $entityId, array $filterOptions = []): ?array
77 if (!is_string($entityId) || !isset(self::$entities[$entityId]))
82 $filterConfigs = self::$filters[$entityId] ??
null;
83 if (!is_array($filterConfigs) || count($filterConfigs) === 0)
89 foreach ($filterOptions as $filterOption)
91 if (!array_key_exists($filterOption[
'id'], $filterConfigs))
97 $className = $filterConfigs[$filterOption[
'id']][
'className'] ??
null;
98 $options = isset($filterOption[
'options']) && is_array($filterOption[
'options']) ? $filterOption[
'options'] : [];
100 $filters[] = self::createFilter($moduleId, $className, $options);
110 return self::$entities;
113 private static function load()
120 foreach (ModuleManager::getInstalledModules() as $moduleId => $moduleDesc)
122 $settings = \Bitrix\Main\Config\Configuration::getInstance($moduleId)->get(
'ui.entity-selector');
123 if (empty($settings) || !is_array($settings))
128 if (!empty($settings[
'extensions']) && is_array($settings[
'extensions']))
130 self::$extensions = array_merge(self::$extensions, $settings[
'extensions']);
133 if (!empty($settings[
'entities']) && is_array($settings[
'entities']))
135 foreach ($settings[
'entities'] as $entity)
137 if (is_array($entity) && !empty($entity[
"entityId"]) && is_string($entity[
"entityId"]))
139 self::$entities[$entity[
"entityId"]] = $entity;
144 if (!empty($settings[
'filters']) && is_array($settings[
'filters']))
146 foreach ($settings[
'filters'] as $filter)
150 && !empty($filter[
'id'])
151 && is_string($filter[
'id'])
152 && !empty($filter[
'entityId'])
153 && is_string($filter[
'entityId'])
154 && !empty($filter[
'className'])
155 && is_string($filter[
'className'])
158 self::$filters[$filter[
'entityId']][$filter[
'id']] = $filter;
164 self::$loaded =
true;
167 private static function createProvider($moduleId, $className, $options = []): ?BaseProvider
169 if (!is_string($className))
174 if (is_string($moduleId))
176 Loader::includeModule($moduleId);
181 $reflectionClass = new \ReflectionClass($className);
182 if ($reflectionClass->isAbstract())
187 if (!$reflectionClass->isSubclassOf(BaseProvider::class))
193 $provider = $reflectionClass->newInstance($options);
198 catch (\ReflectionException $exception)
206 private static function createFilter($moduleId, $className, $options = []): ?BaseFilter
208 if (!is_string($className))
213 if (is_string($moduleId))
215 Loader::includeModule($moduleId);
220 $reflectionClass = new \ReflectionClass($className);
221 if ($reflectionClass->isAbstract())
226 if (!$reflectionClass->isSubclassOf(BaseFilter::class))
232 $filter = $reflectionClass->newInstance($options);
236 catch (\ReflectionException $exception)