I
I
Igor2020-07-08 19:21:50
1C-Bitrix
Igor, 2020-07-08 19:21:50

Subscribe your module to the Bitrix event?

Good afternoon.

Tell me, please, how to subscribe your module to the event?

Everything works if I directly write in /local/php_interface/init.php:

AddEventHandler("main", "OnAdminListDisplay", "MyOnAdminListDisplay");
function MyOnAdminListDisplay(&$list)
{
    #Только для разделов инфоблока
    if (strpos($list->table_id, 'tbl_iblock_section') !== false)
    {
        #Добавляем пункт в контекстное меню
        foreach ($list->aRows as $row)
        {
            $row->aActions["archive"]["ICON"] = "";
            $row->aActions["archive"]["TEXT"] = "Удалить весь сайт нахер";
            $row->aActions["archive"]["ACTION"] = "javascript:archive(".$row->id.")";
        }
    }
}


But I need through the module!

I register an event in the install/index.php module folder:
function InstallEvents()
  {
    $eventManager = \Bitrix\Main\EventManager::getInstance();
    $eventManager->registerEventHandler(
      'main',
      'OnAdminListDisplay',
      self::MODULE_ID,
      'CKrasovskyEvent',
      'eventHandler'
    );

    return true;
  }


In lib/eventhandler.php
class CKrasovskyEvent
{
    function eventHandler(&$list)
    {
        #Только для разделов инфоблока
        if (strpos($list->table_id, 'tbl_iblock_section') !== false)
        {
            #Добавляем пункт в контекстное меню
            foreach ($list->aRows as $row)
            {
                $row->aActions["archive"]["ICON"] = "";
                $row->aActions["archive"]["TEXT"] = "Удалить весь сайт нахер";
                $row->aActions["archive"]["ACTION"] = "javascript:archive(".$row->id.")";
            }
        }
    }
}


But the event does not work, tell me what's wrong

. This item should appear
5f05f37a1b5b8175420327.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question