Form::loadWidgetsDataForEmbed

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. Form
  4. loadWidgetsDataForEmbed
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/controller/form.php
  • Класс: Bitrix\Crm\Controller\Form
  • Вызов: Form::loadWidgetsDataForEmbed
private function loadWidgetsDataForEmbed(int $formId, int $count, string $formType): array
{
	$result = $otherWidgets = [];
	$widgets = \Bitrix\Crm\SiteButton\Internals\ButtonTable::getList(['filter' => ['=ACTIVE' => 'Y']]);

	if (!$widgets) {
		return [];
	}

	$counted = 0;
	foreach ($widgets as $data)
	{
		$button = new Crm\SiteButton\Button();
		$button->loadByData($data);
		$buttonId = $button->getId();
		$formIds = $button->getWebFormIdList();

		if (in_array($formId, $formIds, true))
		{ // collect related widgets
			$result[$buttonId] = $this->constructEmbedWidgetsDataSet($buttonId, $button, $formType, true);
			$counted++;
		}
		else
		{ // collect all other widgets
			$otherWidgets[$buttonId] = $this->constructEmbedWidgetsDataSet($buttonId, $button, $formType, false);
		}

		if ($counted === $count)
		{
			break;
		}
	}

	// merge some more widgets
	$resultCount = count($result);
	if ($resultCount < $count)
	{
		$needMore = $count - $resultCount;
		$moreWidgets = array_slice($otherWidgets, 0, $needMore);
		array_push($result, ...$moreWidgets);
	}

	// fetch all related form names
	$allRelatedFormIds = [];
	foreach ($result as $data)
	{
		$allRelatedFormIds[] = $data['relatedFormIds'];
	}
	$allRelatedFormIds = array_merge([], ...$allRelatedFormIds);
	$formNames = $this->getFormNames($allRelatedFormIds);
	foreach ($result as $btnId => $btnData)
	{
		foreach ($btnData['relatedFormIds'] as $frmId)
		{
			$result[$btnId]['relatedFormNames'][$frmId] = $formNames[$frmId] ?? 'form #' . $frmId;
		}
	}

	return $result;
}

Добавить комментарий