I made a sub-theme of the admin theme "Seven" and called it Seven2 Because I wanted to customize the node-edit-form.twig.html file. That works.

My next step, I want to add a block I made in a custom module, to that node-edit-form.twig.html. There are several ways of doing that, and one I chose is preprocess page (or node for that matter), where I want to load my block.

The preprocess functions can either be in Seven2 .theme file or the custommodule.module file.

When I execute:

$block = \Drupal\block\Entity\Block::load('checkmark_block');

The $block is NULL when I do kint($block). Its like it can't find the damned block!! I have spent like 4 hours trying to make this thing work, in different ways, but no matter what, I can't load that block in my preprocess function. I don't know why but I think it's because it's an admin theme? Or... please help.

One of the blocks located in custommodule/src/Plugin/Block:

namespace Drupal\custommodule\Plugin\Block;
use Drupal\Core\Block\BlockBase;

 * Provides a 'CheckMark' Block.
 * @Block(
 *   id = "checkmark_block",
 *   admin_label = @Translation("CheckMark block"),
 *   category = @Translation("CheckMarks"),
 * )
class CheckMark extends BlockBase {

   * {@inheritdoc}
  public function build() {
    $markup = 'Test test';

    $build = array(
      '#type' => 'markup',
      '#markup' => $markup,
      '#cache' => array('max-age' => 0),

    return $build;


Ok, I made it work by the answer from this post: How can I programmatically display a block?

And rendered it by adding this in hook_form_alter:

if ($form_id == 'node_article_edit_form') {
  ... code from the other post here ... 
  $block = $plugin_block->build();
  $form['checkmark_block'] = $block;

And then in the twig file:

{{ form.checkmark_block }}

I find it way to difficult for a small task like this, and annoying to spend so much time on it, but one hopefully learns by it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.