Documentation

onSuccessRest

Event allows redefining result of any (successful) REST command. This method can change the returned result, but Метод может изменить возвращаемый результат, но не может отменить его на ошибочный.

Parameters

Method Description Available from version
result Method result.
action Array with called method and parameters. Contain the following keys:
  • action - updated REST method, for example, landing.landing.getAdditionalFields transforms to landing::getadditionalfields,
  • class - a called class,
  • method - a called class,
  • >params_init - method parameters.

Example

For method landing.landing.getAdditionalFields:

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('landing', 'onSuccessRest',
   function(\Bitrix\Main\Event $event) use($buildLangFile)
   {
      $result = new \Bitrix\Main\Entity\EventResult();
      $action = $event->getParameter('action');
      $restResult = $event->getParameter('result');

      if (
         is_array($restResult) &&
         strtolower($action['action']) == 'landing::getadditionalfields'
      )
      {
         $restResult = ['my', 'new', 'array'];
         $result->modifyFields([
            'result' => $restResult
         ]);
      }

      return $result;
   }
);


© «Bitrix24», 2001-2024
Up