Documentation

Custom node types

Attention! We strongly recommend first to learn more about Sites module REST documentation to understand how the module functions (with REST available in Bitrix24 Self-hosted editions). View this documentation as useful source when working with Bitrix24 Self-hosted editions and find out more details about API and only REST is not enough.

The system has several preset types of nodes (and +1 Self-hosted type "component"). These types encompass maximally available content for editing and presuppose that it can implement 99% of objectives.

When you you are sure that for your objective, a custom type of node is required, proceed with the following:

  1. Create a descendant class from the abstract class Bitrix\Landing\Node. When you want to modify behaviour of standard types, you can inherit from a suitable class in the namespace Bitrix\Landing\Node.
  2. Realize the following methods in the inherited class:
    • getHandlerJS that returns a string, JS class name for type handler for editor (find more details below),
    • saveNode, handler for saving your content type (modifies using the passed selector and position content according to your logic),
    • getNode, handler for getting your content type (returns array with this type of data using the passed selector; presently used for site export),
    • when required, you can implement the method prepareManifest allowing to update the block manifest until passing to the editor.
  3. This class must be available in the moment of calling the handler for registering your type.
    $eventManager = \Bitrix\Main\EventManager::getInstance();
    $eventManager->addEventHandler('landing', 'onGetNodeClass',
       function(\Bitrix\Main\Event $event)
       {
          $result = new \Bitrix\Main\Entity\EventResult;
          $type = $event->getParameter('type');
          if ($type == 'my_type')
          {
             $result->modifyFields(array(
                'class' => 'MyTypeNode'
             ));
          }
          return $result;
       }
    );
    Specifically this handler will associate your class MyTypeNode with the new type my_type.

A few more details on the JS handler, mentioned above. When a server side is responsible for saving specific data, client side has interfaces for interaction of this node type with user. It is for developer of this node type to decide how such interfaces should look like and how to interact with them. You can find examples in the one of existing JS types at the path /bitrix/js/landing/node.

The type icon is one of the simplest for intuitive understanding in terms of code.


© «Bitrix24», 2001-2024
Up