D
D
Denis Dormadekhin2017-09-04 09:51:54
Design
Denis Dormadekhin, 2017-09-04 09:51:54

How to create a custom action with binding to an element?

Good afternoon! how can I add a custom group action for infoblock elements, using the example of the one on the screen?
c79ce00e3c834676b7895e5c83490649.png
to display a field for selecting an element

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Vorobei, 2019-05-15
@ivanvorobei

You can see blanks on a black background.
Convert to `screen` overlay.

A
Andrey Nikolaev, 2017-09-05
@dormadekhin

Basically it's not difficult.
First, you subscribe to the OnAdminListDisplay event of the Main module.
It is it that is responsible for the action BEFORE displaying any list of elements in the administrative panel (with the exception of sub-lists for infoblocks and the performance module).
It accepts only 1 parameter as input - an instance of the CAdminList class (see /bitrix/modules/main/interface/admin_list.php)
To process the desired table, you need to limit the selection. Those. Your handler will look something like this:

<?php
AddEventHandler("main", "OnAdminListDisplay", "MyOnAdminContextMenuShow");
function MyOnAdminContextMenuShow(&$oAdminList)
{
    /**
     * $type - тип кода инфоблока, например news, events и т.д.
     * $iblock - идентификатор инфоблока
     * 
     * Если интересует каталог, то вместо tbl_iblock_list_ нужно использовать tbl_product_list_
     */
    if ( $oAdminList->table_id == "tbl_iblock_list_".md5($type.".".$iblock) )
    {
        // полезные действия
    }
}
?>

Actually, we get the opportunity to work with the output.
For a more detailed explanation, it is better to read about custom elements in the administrative panel in the documentation: https://dev.1c-bitrix.ru/api_help/main/general/adm... Let's
actually add the data we need for work. Suppose I want to log the selected elements on the page, then my code would look like this:
AddEventHandler("main", "OnAdminListDisplay", "MyOnAdminContextMenuShow");
function MyOnAdminContextMenuShow(&$oAdminList)
{
    /**
     * $type - тип кода инфоблока, например news, events и т.д.
     * $iblock - идентификатор инфоблока
     * 
     * Если интересует каталог, то вместо tbl_iblock_list_ нужно использовать tbl_product_list_
     */
    if ( $oAdminList->table_id == "tbl_iblock_list_".md5("structure.4") )
    {
    	$arActions = $oAdminList->arActions;

    	$arActions['alert'] = 'Ругаться!';

    	$oAdminList->AddGroupActionTable($arActions);
    }
}

AddEventHandler("main", "OnAfterEpilog", "iblockAlert");

function iblockAlert()
{
  $oRequest = \Bitrix\Main\Application::getInstance()->getContext()->getRequest();

  // Проверяем, что работает только в админке
  if ( $oRequest->isAdminSection() )
  {
    if (
      // Интересуют только интерактивные запросы
      $oRequest->get('mode')=='frame'
      // Где передана переменна IBLOCK_ID
      && $oRequest->get('IBLOCK_ID')==4
      // Соответствующие нашему action
      && $oRequest->get('action')=='alert'
      )
    {
      /**
       * Вот тут можно сделать что угодно
       * Можно получить выделенные ID
       * через $oRequest->get('ID')
       * Если он пуст, значит действие на всех элементах инфоблока
       */
    }
  }
}

In fact, there are much more parameters - there are also custom areas that can be displayed, but the essence is the same. If you want to add your own field (I added a simple action), then it's better to look at the source and there, by analogy, sort it out

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question