• Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/lib/Service/Timeline/Item/Activity/ConfigurableRestApp.php
  • Класс: Bitrix\Crm\Service\Timeline\Item\Activity\ConfigurableRestApp
  • Вызов: ConfigurableRestApp::createAction
private function createAction(?ActionDto $actionDto): ?Action
{
	if (!$this->isValidDto($actionDto))
	{
		return null;
	}
	if ($actionDto->type === ActionDto::TYPE_REDIRECT)
	{
		$uri = new Uri($actionDto->uri);
		$action = new Action\Redirect($uri);
		if ($uri->getHost()) // open external links in new window
		{
			$action->addActionParamString('target', '_blank');
		}

		return $action;
	}
	if (
		$actionDto->type === ActionDto::TYPE_REST_EVENT
		|| $actionDto->type === ActionDto::TYPE_OPEN_REST_APP
	)
	{
		$actionParams = $actionDto->actionParams ?? [];
		if ($actionDto->type === ActionDto::TYPE_REST_EVENT)
		{
			$actionParams['entityTypeId'] = $this->getContext()->getEntityTypeId();
			$actionParams['entityId'] = $this->getContext()->getEntityId();
			$actionParams['activityId'] = $this->getActivityId();
			$actionParams['id'] = $actionDto->id;

			$actionParams['APP_ID'] = $this->getRestAppClientId();
			$signedParams = EventHandler::signParams($actionParams);
			$animation = null;
			switch ($actionDto->animationType)
			{
				case ActionDto::ANIMATION_TYPE_DISABLE:
					$animation = Action\Animation::disableBlock()->setForever(true);
					break;
				case ActionDto::ANIMATION_TYPE_LOADER:
					$animation = Action\Animation::showLoaderForItem()->setForever(true);
					break;
			}

			return (new Action\RunAjaxAction('crm.activity.configurable.emitRestEvent'))
				->addActionParamString('signedParams', $signedParams)
				->setAnimation($animation)
			;

		}
		else
		{
			$action = $this->createOpenAppAction();
			foreach ($actionParams as $actionParamName => $actionParamValue)
			{
				$action->addActionParamString((string)$actionParamName, (string)$actionParamValue);
			}

			return $action;
		}
	}

	return null;
}