• Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/templates/selector.php
  • Класс: BitrixSenderTemplatesSelector
  • Вызов: Selector::prepareTemplate
private function prepareTemplate($template)
{
	if (!is_array($template))
	{
		$template = array();
	}

	// type
	if (!isset($template['TYPE']))
	{
		$template['TYPE'] = Type::getCode(Type::ADDITIONAL);
	}
	// type
	if (!isset($template['IS_TRIGGER']))
	{
		$template['IS_TRIGGER'] = false;
	}

	// type
	if (!isset($template['ID']))
	{
		$template['ID'] = ++$this->templateCounter;
	}

	// fields of template
	if (!isset($template['FIELDS']) || !is_array($template['FIELDS']))
	{
		$template['FIELDS'] = [];
	}

	// segments of template
	if (!isset($template['SEGMENTS']) || !is_array($template['SEGMENTS']))
	{
		$template['SEGMENTS'] = [];
	}

	// dispatch of template
	if (!isset($template['DISPATCH']) || !is_array($template['DISPATCH']))
	{
		$template['DISPATCH'] = [];
	}

	// compatibility for mail templates
	if (isset($template['HTML']) && $template['HTML'] && count($template['FIELDS']) === 0)
	{
		$template['FIELDS']['MESSAGE'] = array(
			'CODE' => 'MESSAGE',
			'VALUE' => $template['HTML'],
			'ON_DEMAND' => TemplateTable::isContentForBlockEditor($template['HTML'])
		);
	}

	if (!isset($template['CATEGORY']) || !$template['CATEGORY'])
	{
		$template['CATEGORY'] = $template['TYPE'];
	}

	if (!isset($template['VERSION']) || !$template['VERSION'])
	{
		$template['VERSION'] = 2;
	}

	if (!isset($template['HINT']) || !$template['HINT'])
	{
		$template['HINT'] = '';
	}

	if (!isset($template['HOT']) || !$template['HOT'])
	{
		$template['HOT'] = false;
	}
	$template['HOT'] = (bool) $template['HOT'];

	// default message code is MAIL
	if (!isset($template['MESSAGE_CODE']) || !$template['MESSAGE_CODE'])
	{
		$template['MESSAGE_CODE'] = MessageiBase::CODE_MAIL;
	}

	// compatibility
	if ($template['MESSAGE_CODE'] === MessageiBase::CODE_MAIL)
	{
		$template['IS_SUPPORT_BLOCK_EDITOR'] = $template['FIELDS']['MESSAGE']['ON_DEMAND'] ?? '';
	}

	return $template;
}