8use CBitrixComponentTemplate;
58 parent::__construct($component);
59 $this->componentTemplate =
new CBitrixComponentTemplate();
74 $this->setTemplateName($templateName);
79 if($templatePage !== static::TEMPLATE_PAGE_DEFAULT)
81 $templatePage = static::TEMPLATE_PAGE_DEFAULT;
87 $this->setTemplateName(static::TEMPLATE_NAME_DEFAULT);
93 $this->includeComponentTemplate($templatePage);
97 $this->__showError(str_replace(
100 "Cannot find '#NAME#' template with page '#PAGE#'"
107 $this->
setUserField($this->arParams[
'~userField'] ?? []);
144 return ($this->additionalParameters[$key] ??
null);
168 return $this->__parent;
176 $this->__parent = $_parent;
190 if(!empty($this->additionalParameters[
'mode']))
192 $modes = (is_array($this->additionalParameters[
'mode']) ?
193 $this->additionalParameters[
'mode'] : [$this->additionalParameters[
'mode']]
198 $modes = [static::MODE_DEFAULT];
209 return $this->availableModes;
217 $this->availableModes = $availableModes;
223 $mode = array_shift($availableModes);
230 protected function setMode(
string $mode): void
237 $mediaType = static::MEDIA_TYPE_DEFAULT;
238 if (isset($this->additionalParameters[
'mediaType']) && $this->additionalParameters[
'mediaType'])
240 $mediaType = $this->additionalParameters[
'mediaType'];
251 $this->mediaType = $mediaType;
277 return ($this->
getMode() ?: static::TEMPLATE_NAME_DEFAULT);
298 if(empty($templatePage))
300 $templatePage = $this->getTemplatePage();
311 static $mediaTypes =
null;
312 if($mediaTypes ===
null)
316 return in_array($this->
getMediaType(), $mediaTypes,
true);
324 return $this->
getMediaType() ?: static::MEDIA_TYPE_DEFAULT;
333 $reflection =
new ReflectionClass(__CLASS__);
334 $constants = $reflection->getConstants();
336 foreach($constants as $name => $value)
338 if(mb_strpos($name,
'MEDIA_TYPE_') === 0)
340 $result[$name] = $value;
351 return $this->mediaType;
359 static $checkedTemplateFolders = [];
362 !array_key_exists($this->
getMode(), $checkedTemplateFolders)
364 $checkedTemplateFolders[$this->
getMode()] ===
null
368 $this->componentTemplate->Init($this);
369 $checkedTemplateFolders[$this->
getMode()] = $this->componentTemplate->hasTemplate();
372 return $checkedTemplateFolders[$this->
getMode()];
382 static $availableMode = [];
385 !array_key_exists($availableMethodsKey, $availableMode)
387 $availableMode[$availableMethodsKey] ===
null
395 $availableMode[$availableMethodsKey] = $this->
getMode();
400 return $availableMode[$availableMethodsKey];
417 static $isCheckedTemplatePage =
null;
419 if($isCheckedTemplatePage ===
null)
422 $isCheckedTemplatePage = $this->componentTemplate->hasTemplatePage($templatePage);
425 return $isCheckedTemplatePage;
433 $nameFromAdditionalParameters = ($this->additionalParameters[
'NAME'] ??
null);
434 $nameFromUserField = ($this->userField[
'FIELD_NAME'] ??
null);
436 $fieldName = $nameFromAdditionalParameters ?? $nameFromUserField;
442 if($this->
isMultiple() && !mb_substr_count($fieldName,
'[]'))
455 return (isset($this->userField[
'MULTIPLE']) && $this->userField[
'MULTIPLE'] ===
'Y');
465 if(empty($this->additionalParameters[
'bVarsFromForm']) && !isset($this->additionalParameters[
'VALUE']))
468 isset($this->userField[
'ENTITY_VALUE_ID']) && $this->userField[
'ENTITY_VALUE_ID'] <= 0
469 ? ($this->userField[
'SETTINGS'][
'DEFAULT_VALUE'] ?? [])
470 : ($this->userField[
'VALUE'] ?? [])
473 elseif(isset($this->additionalParameters[
'VALUE']))
475 $value = $this->additionalParameters[
'VALUE'];
477 elseif(isset($this->userField[
'FIELD_NAME']))
491 if(!is_array($value))
493 $value = array($value);
497 $value = array(
null);
508 if(!array_key_exists(static::getUserTypeId(), self::$htmlBuilder))
513 return self::$htmlBuilder[static::getUserTypeId()];
521 self::$htmlBuilder[static::getUserTypeId()] =
$htmlBuilder;
529 return ($this->
getMediaType() === static::MEDIA_TYPE_DEFAULT);
537 return ($this->
getMediaType() === static::MEDIA_TYPE_MOBILE);
setMediaType(string $mediaType)
const TEMPLATE_PAGE_DEFAULT
__construct($component=null)
isExistTemplatePage(?string $templatePage='')
static normalizeFieldValue($value)
hasTemplatePage(string $templatePage)
getTemplateNameFromMode()
const TEMPLATE_NAME_DEFAULT
setAvailableModes(array $availableModes)
setParentComponent(?CBitrixComponent $_parent)
generateAvailableModesHash()
setAdditionalParameters(?array $additionalParameters)
getTemplatePageFromMediaType()
getAdditionalParameter(string $key)
setHtmlBuilder(HtmlBuilder $htmlBuilder)
getAvailableTemplateFolder()
getAdditionalParameters()