entityTypeManager->getStorage('block_content')->getQuery() ->condition('type', $this->entity->id()) ->execute(); if (!empty($blocks)) { $caption = '

' . $this->formatPlural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', ['%label' => $this->entity->label()]) . '

'; $form['description'] = ['#markup' => $caption]; return $form; } else { return parent::buildForm($form, $form_state); } } }