Documentation

setClasses

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.

public function setClasses(
   $data
)

Changes sets of classes by selector. Returns true on success.

Parameters

ParameterDescriptionVersion
dataParameter passes key-value array, where key is selector and each value has two arrays specified:
  • classList - which classes to add into updated selector.
  • affect - passes styles to be zeroed-out for all child nodes. For example, passes class that colors an item into specific color. Pass the array [color] to affect for system to reset all color parameters for child nodes. Otherwise situation is: parent color is a new red, but text inside is still hasn't changed.

Selector can be passed with position indicator (for example, .landing-block-node-text), then all cards are updated as per this selector - as well as with position indicated (for example, .landing-block-node-text@2), then updates only the card on the specified position (counting from zero).

Example

if (\Bitrix\Main\Loader::includeModule('landing'))
{
   \Bitrix\Landing\Landing::setEditMode(true);

   $landing = \Bitrix\Landing\Landing::createInstance(
      5675
   );
   if ($landing->exist())
   {
      foreach ($landing->getBlocks() as $block)
      {
         if ($block->getId() == 45474)
         {
            $block->setClasses([
               '.landing-block-node-title@1' => [
                  'classList' => [
                     'landing-block-node-title', 'g-color-gray-light-v2', 'text-right'
                  ],
                  'affect' => [
                     'text-align'
                  ]
               ]
            ]);
            $block->save();
            $landing->getError()->copyError(
               $block->getError()
            );
         }
      }
   }


   foreach ($landing->getError()->getErrors() as $error)
   {
      echo $error->getCode() . ': ';
      echo $error->getMessage();
      echo "\n";
   }
} 


© «Bitrix24», 2001-2024