• Модуль: landing
  • Путь к файлу: ~/bitrix/modules/landing/lib/hook/page/theme.php
  • Класс: BitrixLandingHookPageTheme
  • Вызов: Theme::exec
public function exec(): void
{
	$defaultColors = self::getColorCodes();

	// get color from request or from settings
	$request = Application::getInstance()->getContext()->getRequest();
	if ($request->get('color'))
	{
		$colorHex = $request->get('color');
	}
	elseif (
		($themeCodeFromRequest = $request->get('theme'))
		&& array_key_exists($themeCodeFromRequest, $defaultColors)
	)
	{
		$themeCode = $themeCodeFromRequest;
		$colorHex = $defaultColors[$themeCodeFromRequest]['color'];
	}
	else
	{
		$colorHex = HtmlFilter::encode(trim($this->fields['COLOR']->getValue()));
		if (!$colorHex)
		{
			$themeCode = HtmlFilter::encode(trim($this->fields['CODE']->getValue()));
			$colorHex = $themeCode ? $defaultColors[$themeCode]['color'] : self::DEFAULT_COLOR;
		}
	}

	if (!is_string($colorHex))
	{
		$colorHex = '';
	}
	$colorHex = self::prepareColor($colorHex);

	$restrictionCode = RestrictionHook::getRestrictionCodeByHookCode('THEME');
	if (
		!RestrictionManager::isAllowed($restrictionCode)
		&& !self::getThemeCodeByColor($colorHex)
	)
	{
		$colorHex = self::DEFAULT_COLOR;
	}

	// print
	$rgbColor = self::convertHexToRgb($colorHex);
	$rgbTemplate = $rgbColor[0] . ', ' . $rgbColor[1] . ', ' . $rgbColor[2];
	$hslColor = self::convertRgbToHsl($rgbColor[0], $rgbColor[1], $rgbColor[2]);

	if (
		isset($themeCode)
		|| ($themeCode = self::getThemeCodeByColor($colorHex))
	)
	{
		$colorMain = $defaultColors[$themeCode]['main'] ?? null;
		if ($defaultColors[$themeCode]['secondary'] ?? null)
		{
			$colorSecondary = $defaultColors[$themeCode]['secondary'];
		}
		if ($defaultColors[$themeCode]['colorTitle'] ?? null)
		{
			$colorTitle = $defaultColors[$themeCode]['colorTitle'];
		}
	}
	$colorMain = $colorMain ?? 'hsl('.$hslColor[0].', 20%, 20%)';
	$colorSecondary = $colorSecondary ?? 'hsl('.$hslColor[0].', 20%, 80%)';
	$colorTitle = $colorTitle ?? $colorMain;

	if ($hslColor[2] > 60)
	{
		$colorStrictInverseFromPrimary = '#000000';
	}
	else
	{
		$colorStrictInverseFromPrimary = '#ffffff';
	}

	Asset::getInstance()->addString(
		'',
		false,
		AssetLocation::BEFORE_CSS
	);
}