How to get a machine name of a custom block I have a custom "Slider Items" field type, as well as the custom "Channel Slider Block Type" type block (created using "Custom block library").





Also, I have several "Channel Slider Block Type" blocks.  I need to somehow determine the machine name of a block that this field displays in @FieldFormatter of my field. How can this be implemented? Perhaps there is a special service for this?


/**
 * @FieldFormatter(
 *   id = "channel_slider_formatter",
 *   label = @Translation("Channel Slider Formatter"),
 *   field_types = {
 *     "channel_slider"
 *   }
 * )
 */
class ChannelSliderFormatter extends FormatterBase {

  public function viewElements(FieldItemListInterface $items, $langcode) {
    // Here I need to get a block that reflects this field.
    $blockMachineName = '...';
    ...
    return [
      '#theme' =&gt; 'channel_slider',
      '#items' =&gt; $itemsData,
    ];
  }

}
A custom content block has no unique machine name, only a bundle type, an UUID and an ID. Only custom content blocks placed in a region have a machine name, but this is NOT the machine name of the block, it is the machine name of the block placement (configuration)